webR-enabled code cells

Live R in quarto documents using web-r quarto extension

Author

Roy Francis

Published

06-Sep-2024

1 Installation

Install webr extension for quarto by running:

quarto add coatless/quarto-webr

then add to yaml:

webr:
   channel-type: "post-message"
engine: knitr
filters:
  - webr

webR-enabled code cell are established by using {webr-r} in a Quarto HTML document.

2 Sample cases

2.1 Fit a linear regression model

2.2 Create a graph with base R

2.3 Packages

2.3.1 Available Packages

You can view what packages are available for webR by either executing the following R code (either with WebR or just R). This chunk is an R chunk that is not evaluated.

available.packages(
  repos = "https://repo.r-wasm.org/",
  type = "source"
)[, c("Package", "Version")]

Or, by navigating to the WebR repository:

https://github.com/r-wasm/webr-repo/blob/main/repo-packages

2.3.2 Installing a Package

Installing ggplot2 may take at least 2 minutes to run.

2.3.3 Using a Package

Once ggplot2 is loaded, then use the package as normal.

2.4 Define variables and re-use them in later cells

2.5 Escape characters in a string

2.6 Anonymous function definition

2.7 Empty code cell

2.8 Pre-rendered R code cell

message("Hello!")
Hello!

3 Session

webr extension version: 0.3.6