-
Notifications
You must be signed in to change notification settings - Fork 41
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
Functions for interacting with objects created by student code #333
Conversation
R/user_object.R
Outdated
#' @usage NULL | ||
user_object <- function(x, mode, envir, exclude_envir, ..., gradethis_env) NULL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This dummy function only exists to force roxygen to document params in the correct order (r-lib/roxygen2#1475)
|
…ted while running solution code
1a18ef3
to
76c1ab9
Compare
9ab9c1d
to
bc9b056
Compare
R/user_object.R
Outdated
|
||
#' @rdname user_object | ||
#' @export | ||
solution_object_get <- function( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: is .solution
not yet evaluated until any one of these solution_object_*()
are called or a force(.solution)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's right, when we enter grade_this()
, the -solution
chunk has not yet been evaluated. Resolving .solution
here ensures that it's evaluated so that we can check its environment for objects. If the author happened to call a function that uses .solution
earlier in their grading code, then resolving it here just does nothing.
R/user_object.R
Outdated
x, mode = "any", ..., gradethis_env = parent.frame() | ||
) { | ||
resolve_placeholder(.solution, gradethis_env) | ||
user_object_get( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should have a more basic object_get()
where we then pass in the appropriate envir
depending on if we're calling a user_object_*()
or solution_object_*()
? This slightly confused me at first since it was a call to user_object_get()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That seems like a good idea to me! I think it makes sense to just make those internal functions, right? Since I can't really see a use case for a generic object_get()
that's not already covered by user_object_get()
, solution_object_get()
, or just plain old get()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that's exactly what I was thinking of, make object_get()
internal that these public ones call.
@@ -307,6 +307,8 @@ prepare_check_env <- function( | |||
check_env[[".solution_code"]] <- solutions[[length(solutions)]] | |||
} | |||
|
|||
check_env[[".envir_solution"]] <- envir_base |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exciting! 🚀
…t_*()` functions to use internal `object_*()` implementation functions
user_object_get()
returns an object created by the student's code.user_object_exists()
checks if an object was created by the student's code.user_object_list()
lists objects created by the student's code.solution_object_get()
returns an object created by the solution code.solution_object_exists()
checks if an object was created by the solution code.solution_object_list()
lists objects created by the solution code.Closes #291 and closes #268.
This PR also introduces the
with_exercise()
helper function, which runs an expression as if it were in an exercise'sgrade_this()
block.This function is primarily useful for running gradethis functions outside the context of a learnr tutorial, e.g. for examples or testing.