Access envir_result inside -check chunk


The learnr tutorial states the following:

Checker Function

What the code within the “-check” chunk actually does will vary depending on which exercise checker is currently active. The exercise checker function is passed various arguments which provide the context required to check the user’s exercise input:

Argument Description
label Label for exercise chunk.
user_code R code submitted by the user.
solution_code Code provided within the “-solution” chunk for the exercise.
check_code Code provided within the “-check” chunk for the exercise.
envir_result The R environment after the execution of the chunk.
evaluate_result The return value from the evaluate::evaluate function.
envir_prep A copy of the R environment before the execution of the chunk.
last_value The last value of the evaluated chunk.
Unused (include for compatibility with parameters to be added in the future)

I'm trying to access the environment after the code is run (envir_result). The intent is to check that the student successfully created an object and to check values inside that object. In this case, it's a lm object.

Here is my code:

```{r two-plus-two, exercise=TRUE}
lm1 <- lm(mpg~cyl+ hp, mtcars)
```{r two-plus-two-check}

  pass_if(check_environment(~ .envir_result, contains = "lm1"), message = "Good job! You created the lm1 object.")

So, how do I access envir_result?

Any help would be appreciated. I have tried a number of things without any luck. Thanks in advance.

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.