diff --git a/DESCRIPTION b/DESCRIPTION index 3f4aafde..2b973a18 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -40,7 +40,8 @@ Suggests: testthat (>= 3.1.5), withr (>= 2.0.0) VignetteBuilder: - knitr + knitr, + rmarkdown RdMacros: lifecycle Config/Needs/verdepcheck: mllg/checkmate, r-lib/lifecycle, r-lib/rlang, diff --git a/vignettes/qenv.Rmd b/vignettes/qenv.Rmd index 6866c59a..00fbf4ba 100644 --- a/vignettes/qenv.Rmd +++ b/vignettes/qenv.Rmd @@ -26,18 +26,17 @@ print(empty_qenv) ### `qenv` basic usage -The `eval_code()` function executes code within a `qenv` environment, yielding a new `qenv` object as the output. +The `eval_code()` function executes code within a `qenv` environment, yielding a new `qenv` object as the output. ```{r} -library(magrittr) - # evaluate code in qenv my_qenv <- eval_code(empty_qenv, "x <- 2") print(my_qenv) get_env(my_qenv) -q1 <- eval_code(my_qenv, "y <- x * 2") %>% eval_code("z <- y * 2") +q1 <- eval_code(my_qenv, "y <- x * 2") +q1 <- eval_code(q1, "z <- y * 2") # my_qenv still contains only x print(my_qenv) @@ -50,7 +49,8 @@ ls(get_env(q1)) The same result can be achieved with the `within` method for the `qenv` class. ```{r} -q2 <- within(my_qenv, y <- x * 2) %>% within(z <- y * 2) +q2 <- within(my_qenv, y <- x * 2) +q2 <- within(q2, z <- y * 2) print(q2) ``` @@ -66,7 +66,7 @@ cat(get_code(q2)) ``` ### Substitutions -In some cases, one may want to substitute some elements of the code before evaluation. +In some cases, one may want to substitute some elements of the code before evaluation. Consider a case when a subset of `iris` is defined by an input value. ```{r} q <- qenv() @@ -147,11 +147,11 @@ These functions can be seamlessly integrated into `shiny` applications to produc When employing a `qenv` to evaluate code, should an error occur, an object of type `qenv.error` is generated. This object can be utilized wherever a `qenv` object is used, alleviating the need for code alterations to handle these errors. Select the `error_option` in the example below to witness `qenv` error handling in action. -```{r} +```{r, eval=requireNamespace("shiny")} library(shiny) -library(magrittr) # create an initial qenv with the data in -data_q <- qenv() %>% eval_code("iris_data <- iris") +data_q <- qenv() +data_q <- eval_code(data_q, "iris_data <- iris") ui <- fluidPage( radioButtons(