safe: Execute R code in a safe R environment

Description Usage Arguments Details Examples

View source: R/run.R

Description

When rendering (or running) a document with R markdown, it inherits the current R Global environment. This will produce unexpected behaviors, such as poisoning the R Global environment with existing variables. By rendering the document in a new, safe R environment, a vanilla, rendered document is produced.

Usage

1
safe(expr, ..., show = TRUE, env = safe_env())

Arguments

expr

expression that contains all the necessary library calls to execute. Expressions within callr do not inherit the existing, loaded libraries.

...

parameters passed to callr::r

show

Logical that determines if output should be displayed

env

Environment to evaluate the document in

Details

The environment variable LEARNR_INTERACTIVE will be set to "1" or "0" depending on if the calling session is interactive or not.

Using safe should only be necessary when locally deployed.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
## Not run: 
# Direct usage
safe(run_tutorial("hello", package = "learnr"))

# Programmatic usage
library(rlang)

expr <- quote(run_tutorial("hello", package = "learnr"))
safe(!!expr)

tutorial <- "hello"
safe(run_tutorial(!!tutorial, package = "learnr"))

## End(Not run)

learnr documentation built on March 26, 2020, 7:45 p.m.