R code
R cells run in webR, a build of R for the browser. Real Quarto runs R through knitr; the playground imitates knitr’s output, producing the same markdown and cell attributes as Quarto’s knitr hooks, so cell options, figures and cross-references render the way they do in Quarto.
webR downloads the first time a playground on the page has R code. After that, every playground on the page shares one R session, and each render starts with a fresh environment, as a new quarto render would.
Cell options and output
Supported cell options:
echo(includingecho: fenced),eval,include,output(includingoutput: asis),warning,messageanderrorlabel,fig-cap,fig-alt,fig-widthandfig-height, also set for the whole document underexecute:or at the top levelcode-fold,code-summary,code-line-numbersandcode-overflowclasses,column,panelandlayout-ncol/layout-nrow- Header options in knitr style, such as
```{r label, echo=FALSE}
Inline code, `{r} expr`, is evaluated in the same environment as the cells. To show a cell verbatim, fences included, double the braces: ```{r}.
Errors
Without error: true, an error stops the render, as in Quarto. The message says which cell failed and which lines, and suggests error: true:
Packages
library(), require() and pkg::fn() install packages on first use from the webR package repository, which builds most of CRAN. The status line shows the progress. Large packages take a while the first time, so this playground waits for ▶ Render:
Differences from knitr
- Plots are drawn on webR’s canvas device and shown as PNG images. Each plot appears after the last expression that drew on it, as with knitr.
- Printing follows R’s own
print(). Rich output from packages that useknit_print()methods (for exampleknitr::kable()tables) prints as text. - Not available: reading local files,
cache,childdocuments, other knitr engines (bash,sql), andhtmlwidgets. - Infinite loops can’t be interrupted. The learner has to reload the page. Interrupting webR needs cross-origin isolation headers on the site.