Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

206 fix failed pipeline #207

Merged
merged 5 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
18 changes: 9 additions & 9 deletions vignettes/qenv.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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)
donyunardi marked this conversation as resolved.
Show resolved Hide resolved

# 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)
Expand All @@ -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)
```

Expand All @@ -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()
Expand Down Expand Up @@ -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(
Expand Down
Loading