Description Usage Arguments Details Value See Also
View source: R/populate_soln_env.R
Generates objects for checking solution correctness.
1 2 3 4 5 6 7 | populate_soln_env(
soln_fname,
pattern,
knit_root_dir,
render_only = FALSE,
output = NULL
)
|
soln_fname |
An rmd file containing the checks to be run on the student solution. |
pattern |
The pattern that identifies which chunks in the solution are are testing chunks. If this argument is missing, the default pattern used is "test". |
knit_root_dir |
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'). |
render_only |
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. |
output |
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 check_correctness
.
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.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.