publish_snippet()
Publish a notebook chunk as a code snippet
Publishes a chunk of a Quarto or R Markdown notebook to Framework Cloud as a code snippet: its code and the text it printed, as the rendered notebook shows them. A blog post or report can embed the snippet beside the results it produced.
Usage
publish_snippet(
label,
folded = NULL,
output = TRUE,
links = NULL,
slug = NULL,
title = NULL,
description = NULL,
visibility = NULL,
password = NULL,
collection = NULL,
share_unlisted = FALSE,
to = NULL,
repository = NULL,
include_private = FALSE
)
Arguments
| Name | Default | Description |
|---|---|---|
| label |
The chunk label, as in |
|
| folded | NULL |
|
| output | TRUE |
|
| links | NULL |
Links shown with the snippet:
|
| slug | NULL |
Artifact slug. Default: the label, lowercased, with other
characters as |
| title | NULL |
Artifact title. Default: the label. |
| description | NULL |
Artifact description. |
| visibility | NULL |
|
| password | NULL |
Password required to view the snippet on Framework Cloud. |
| collection | NULL |
Existing project collection ID or slug. |
| share_unlisted | FALSE |
Consent to share an unlisted snippet with collection readers. |
| to | NULL |
Publishing destination. See |
| repository | NULL |
Repository URL to name in the snippet, such as
|
| include_private | FALSE |
Skip the private-data confirmation. See |
Value
The artifact URL, invisibly, or NULL when nothing was published.
Details
Under quarto render or rmarkdown::render(), library(framework) records each chunk's code, printed output, messages, warnings, and errors as knitr renders them. Chunk options therefore apply: echo = FALSE leaves out the code, and results = "hide", message = FALSE, and warning = FALSE leave out those outputs. Plots are not recorded. Output shown with results = "asis" is not recorded either, because knitr passes it straight to the document. knitr's comment prefix (##) is removed.
Call publish_snippet() in any chunk after the labelled one, usually a chunk with include: false. The labelled chunk must run after library(framework) (or scaffold()), and not from the knitr cache.
Outside a render, as when a chunk runs in the editor, nothing has been recorded. publish_snippet() then publishes nothing and says why. It never runs the chunk again.
The snippet names its source: the language, the file's path from the git repository's top (or the project root), the chunk label, the chunk's code lines, and the commit checked out. The repository URL is sent only when repository is given or publish.repository is set in settings.yml. Framework Cloud builds a GitHub permalink from a GitHub repository, the commit, the file, and the lines.
Framework Cloud highlights the code, converts ANSI colors in output, and shortens long output. When the snippet matches its newest version, Cloud adds no version and the message says it is unchanged.
Examples
Not run
if (FALSE) {
# In a Quarto notebook, after a chunk labelled fit-model:
publish_snippet("fit-model", links = list(notebook = "https://example.org/analysis"))
# The code alone
publish_snippet("fit-model", output = FALSE, slug = "fit-model-code")
}