To use gradethis in your learnr tutorial, you only need to call
library(gradethis)
in your tutorial's setup chunk.
```{r setup}
library(learnr)
library(gradethis)
```
Use gradethis_setup()
to change the default options suggested by gradethis.
This function also describes in detail each of the global options available
for customization in the gradethis package. Note that you most likely do not
want to change the defaults values for the learnr tutorial options that are
prefixed with exercise.
. Each of the gradethis-specific arguments sets a
global option with the same name, prefixed with gradethis.
. For example,
pass
sets gradethis.pass
.
Usage
gradethis_setup(
pass = NULL,
fail = NULL,
...,
code_correct = NULL,
code_incorrect = NULL,
maybe_code_feedback = NULL,
maybe_code_feedback.before = NULL,
maybe_code_feedback.after = NULL,
pass.praise = NULL,
fail.hint = NULL,
fail.encourage = NULL,
pipe_warning = NULL,
grading_problem.message = NULL,
grading_problem.type = NULL,
error_checker.message = NULL,
allow_partial_matching = NULL,
exercise.checker = gradethis_exercise_checker,
exercise.timelimit = NULL,
compare_timelimit = NULL,
exercise.error.check.code = NULL,
fail_code_feedback = NULL
)
Arguments
- pass
Default message for
pass()
. Setsoptions("gradethis.pass")
- fail
Default message for
fail()
. Setsoptions("gradethis.fail")
- ...
Arguments passed on to
learnr::tutorial_options
exercise.cap
Caption for exercise chunk (defaults to the engine's icon or the combination of the engine and
" code"
).exercise.eval
Whether to pre-evaluate the exercise so the reader can see some default output (defaults to
FALSE
).exercise.lines
Lines of code for exercise editor (defaults to the number of lines in the code chunk).
exercise.blanks
A regular expression to be used to identify blanks in submitted code that the user should fill in. If
TRUE
(default), blanks are three or more underscores in a row. IfFALSE
, blank checking is not performed.exercise.completion
Use code completion in exercise editors.
exercise.diagnostics
Show diagnostics in exercise editors.
exercise.startover
Show "Start Over" button on exercise.
exercise.reveal_solution
Whether to reveal the exercise solution if a solution chunk is provided.
- code_correct
Default
correct
message forgrade_this_code()
. If unset,grade_this_code()
falls back to the value of thegradethis.pass
option. Sets thegradethis.code_correct
option.- code_incorrect
Default
incorrect
message forgrade_this_code()
. If unsetgrade_this_code()
falls back to the value of thegradethis.fail
option. Sets thegradethis.code_incorrect
option.- maybe_code_feedback
Logical
TRUE
orFALSE
to determine whethermaybe_code_feedback()
should return code feedback, where ifFALSE
,maybe_code_feedback()
will return an empty string.maybe_code_feedback()
is used in the default messages whenpass()
orfail()
are called without any arguments, which are set by thepass
orfail
arguments ofgradethis_setup()
.- maybe_code_feedback.before, maybe_code_feedback.after
Text that should be added
before
orafter
themaybe_code_feedback()
output, if any is returned. Sets the default values of thebefore
andafter
arguments ofmaybe_code_feedback()
.- pass.praise
Logical
TRUE
orFALSE
to determine whether a praising phrase should be automatically prepended to anypass()
orpass_if_equal()
messages. Sets thegradethis.pass.praise
option.- fail.hint
Logical
TRUE
orFALSE
to determine whether an automated code feedback hint should be shown with afail()
orfail_if_equal()
message. Sets thegradethis.fail.hint
option.- fail.encourage
Logical
TRUE
orFALSE
to determine whether an encouraging phrase should be automatically appended to anyfail()
orfail_if_equal()
messages. Sets thegradethis.fail.encourage
option.- pipe_warning
The default message used in
pipe_warning()
. Sets thegradethis.pipe_warning
option.- grading_problem.message
The feedback message used when a grading error occurs. Sets the
gradethis.grading_problem.message
option.- grading_problem.type
The feedback type used when a grading error occurs. Must be one of
"success"
,"info"
,"warning"
(default),"error"
, or"custom"
. Sets thegradethis.grading_problem.type
option.- error_checker.message
The default message used by gradethis's default error checker,
gradethis_error_checker()
. Sets thegradethis.error_checker.message
option.- allow_partial_matching
Logical
TRUE
orFALSE
to determine whether partial matching is allowed ingrade_this_code()
. Sets thegradethis.allow_partial_matching
option.- exercise.checker
Function used to check exercise answers (e.g.,
gradethis::grade_learnr()
).- exercise.timelimit
Number of seconds to limit execution time to (defaults to
30
).- compare_timelimit
pass_if_equal()
andfail_if_equal()
callwaldo::compare()
internally. This helps ensure an accurate comparison, but sometimes takes a long time.compare_timelimit
is the time limit in seconds for the execution ofwaldo::compare()
(defaults to 80% ofexercise.timelimit
). If the time limit is exceeded,identical()
is used instead ofwaldo::compare()
.- exercise.error.check.code
A string containing R code to use for checking code when an exercise evaluation error occurs (e.g.,
"gradethis::grade_code()"
).- fail_code_feedback
Deprecated. Use
maybe_code_feedback
.
Value
Invisibly returns the global options as they were prior to setting
them with gradethis_setup()
.
Global package options
These global package options can be set by gradethis_setup()
or by
directly setting the global option. The default values set for each option
when gradethis is loaded are shown below.
Option | Default Value |
gradethis.pass | "{gradethis::random_praise()} Correct!" |
gradethis.pass.praise | FALSE |
gradethis.fail | "Incorrect.{gradethis::maybe_code_feedback()} {gradethis::random_encouragement()}" |
gradethis.fail.hint | FALSE |
gradethis.fail.encourage | FALSE |
gradethis.maybe_code_feedback | TRUE |
gradethis.maybe_code_feedback.before | " " |
gradethis.maybe_code_feedback.after | NULL |
gradethis.code_correct | NULL |
gradethis.code_incorrect | "{gradethis::pipe_warning()}{gradethis::code_feedback()} {gradethis::random_encouragement()}" |
gradethis.pipe_warning | "I see that you are using pipe operators (e.g. %>%), so I want to let you know that this is how I am interpreting your code before I check it:\n\n```r\n{.user_code_unpiped}\n```\n\n" |
gradethis.grading_problem.message | "A problem occurred with the grading code for this exercise." |
gradethis.grading_problem.type | "warning" |
gradethis.allow_partial_matching | NULL |
gradethis.error_checker.message | "An error occurred with your code:\n\n```\n{.error$message}\n```\n\n\n" |
gradethis.compare_timelimit | NULL |
Examples
# Not run in package documentation because this function changes global opts
if (FALSE) {
old_opts <- gradethis_setup(
pass = "Great work!",
fail = "{random_encouragement()}"
)
}
# Use getOption() to see the default value
getOption("gradethis.pass")
#> [1] "{gradethis::random_praise()} Correct!"
getOption("gradethis.maybe_code_feedback")
#> [1] TRUE