-
Notifications
You must be signed in to change notification settings - Fork 239
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
Detect blanks with exercise.blanks
opt, and add parse checking
#547
Conversation
render_exercise()
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 looks great, thank you!
One design question: In gradethis
we give users an (undocumented) option as a way to turn this off or modify how unparseable code is handled. Should we also do that in learnr? Perhaps an option analogous to exercise.error.check.code
, e.g. exercise.error.parse.check
. (There may already be a better option in use in learnr.)
Are you thinking an |
Co-authored-by: Garrick Aden-Buie <garrick@adenbuie.com>
…ity checking if `FALSE`
|
Running into a few test failures on old releases because the new code uses
For now I've included it as an internal function in |
Here's the current state of the checking:
|
- `check_blanks()` -> `exercise_check_code_for_blanks()` - `check_parsable()` -> `exercise_check_code_is_parsable()`
These changes look good to me! |
Return nothing to better signal this function is called for side-effects, not return values
When the `oxford_comma` argument was added to `knitr::combine_words()`
Conflicts: NEWS.md R/knitr-hooks.R
exercise.blanks
opt, and add parse checking
This PR modifies
evaluate_exercise()
to check whether submitted code contains blanks and whether submitted code cannot be parsed.If submitted code is unparsable, the R error message is rendered along with a message copied from
gradethis
explaining that the code could not be parsed and hinting at common causes of this problem.One special case of unparsability is code that contains blanks. Often, tutorial authors will include blanks in their prompts or hints for students to fill in with valid code, e.g.
___(___, na.rm = TRUE)
. If submitted code contains blanks, evaluation proceeds as normal, but any feedback is replaced by a message explaining that the submitted code contains blanks and showing what blanks in the exercise look like. This applies even if the code containing blanks is parsable, e.g. if the blank is within a character string. To achieve this, the functionreturn_if_exercise_result()
is added withinevaluate_exercise()
. Each existing check (result check, code check, and error check) is wrapped within that function. This function initiates an early return if a result is signalled, but replaces the feedback with feedback about blanks if blanks are present in the user's code.By default, any string of three or more underscores is considered to be a blank. This is the most common pattern in existing tutorials. But this definition can be changed with the
exercise.blanks
chunk option, which accepts a regex pattern to detect as blanks. For example, using{r exercise-check, exercise.blanks = "\\.{3,}"}
as a chunk header would detect series of three or more dots as blanks.Both unparsable and blanks messages are implemented with
i18next
keys, allowing them to be translated into the same language as the rest of thelearnr
interface. Instead of producing raw text when encountering unparsable code or code containing blanks, R generates aspan
tag withdata-i18n
attributes that are replaced with the correct localized text by thei18next
JavaScript library on render. This PR will necessitate adding translations forblank
,blank_plural
,exercisecontainsblank
,pleasereplaceblank
,unparsable
,and
, andor
.