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

Helper function to find object in .envir_result #291

Closed
gadenbuie opened this issue Mar 1, 2022 · 0 comments · Fixed by #333
Closed

Helper function to find object in .envir_result #291

gadenbuie opened this issue Mar 1, 2022 · 0 comments · Fixed by #333
Assignees

Comments

@gadenbuie
Copy link
Member

Occasionally grading authors need to find objects that should have been created by submitted code. There are several base-R functions that can help with this process, but we could provide a nicer interface around the interaction.

pkgload::load_all()
#> ℹ Loading gradethis
library(dplyr, warn.conflicts = FALSE)

ex <- mock_this_exercise({
  mtcars_table <- as_tibble(mtcars)
  mtcars_cyl_6 <- mtcars_table[mtcars_table$cyl == 6, ]
})

The user created the mtcars_cyl_6 object…

exists("mtcars_cyl_6", ex$.envir_result, inherits = FALSE)
#> [1] TRUE

…but we expected mtcars_tbl.

exists("mtcars_tbl", ex$.envir_result, inherits = FALSE)
#> [1] FALSE

Here’s everything in the user result env:

ls(ex$.envir_result)
#> [1] "mtcars_cyl_6" "mtcars_table"

What’s a possible match?

agrep("mtcars_tbl", ls(ex$.envir_result), value = TRUE)
#> [1] "mtcars_table"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants