Generates objects for checking solution correctness.
render_only = FALSE,
output = NULL
An rmd file containing the checks to be run on the student solution.
The pattern that identifies which chunks in the solution are are testing chunks. If this argument is missing, the default pattern used is "test".
The root directory to use for knitting the rmd file. This argument is optional. If it is missing, it uses the root directory in knitr::opts_knit$get('root.dir').
A logical value. If this is TRUE, then the solution is run and rendered. In this case, a list of length two is returned. If this is FALSE (default), then then a list of length three is returned. See the Return section for more details.
The path to the knitted solution md file. This is usually
deleted immediately, but sometimes we may want to keep it. This
argument is passed on to
Test code should be written in a chunk that generates scalars from student objects.
The solution file has to be an Rmd file (not an R script), because it relies on the autoharp.obj and autoharp.scalars knitr hooks being present.
In addition, if it is required that a solution object is to be tested against the analogous object within the student environment, these objects should be listed within the autoharp option of a code chunk. These objects will be copied with the "." preffix.
Here is an overview of how the function works:
Knit the solution file to generate the solution (or "correct") objects.
Rename these with the "." prefix in the solution environment object.
Extract the lines of test code into a temporary R script.
Wrap those chunks that contain autoharp.scalars hook with tryCatch.
Add a few lines at the bottom of the script to indicate which scalars should be kept.
Return the solution environment and path to the R test script.
Typically, the next step is to call
If render_only is FALSE, a list containing 2 components: the environment populated by the solution rmd and the path to an R script containing the test code.
If render_only is TRUE, then the output list contains the aforementioned environment, and the path to the rendered solution file (html). This option is useful for debugging the solution file.