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

Functions for interacting with objects created by student code #333

Merged
merged 14 commits into from
Mar 24, 2023

Conversation

rossellhayes
Copy link
Contributor

@rossellhayes rossellhayes commented Mar 21, 2023

  • 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's grade_this() block.
This function is primarily useful for running gradethis functions outside the context of a learnr tutorial, e.g. for examples or testing.

@rossellhayes rossellhayes self-assigned this Mar 21, 2023
R/user_object.R Outdated
Comment on lines 21 to 22
#' @usage NULL
user_object <- function(x, mode, envir, exclude_envir, ..., gradethis_env) NULL
Copy link
Contributor Author

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)

@rossellhayes
Copy link
Contributor Author

rossellhayes commented Mar 21, 2023

R/user_object.R Outdated

#' @rdname user_object
#' @export
solution_object_get <- function(
Copy link
Contributor

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)?

Copy link
Contributor Author

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(
Copy link
Contributor

@nischalshrestha nischalshrestha Mar 23, 2023

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()

Copy link
Contributor Author

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().

Copy link
Contributor

@nischalshrestha nischalshrestha Mar 23, 2023

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exciting! 🚀

@rossellhayes rossellhayes merged commit 935e1c0 into main Mar 24, 2023
@rossellhayes rossellhayes deleted the feat/user_object branch March 24, 2023 01:41
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 this pull request may close these issues.

Helper function to find object in .envir_result Grading based on object(s) in .result and .solution
2 participants