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

Provides instructions on parse error caused by code scaffolding in learnr tutorial #153

Merged
merged 11 commits into from Dec 8, 2020

Conversation

gadenbuie
Copy link
Member

@gadenbuie gadenbuie commented Sep 28, 2020

Fixes #134

Currently, the code scaffolding commonly used in exercises, e.g. ____(mtcars, ____), causes a parse error, resulting in an error message like the one below:

image

This PR adds logic to the default user code error handler in grade_learnr() to detect three or more _ in the user code and produce an informative error message with instructions.

image

Because the logic adds a bit of complexity to the error handler, I moved the default handler into a new function: grade_learnr_parse_error().

@gadenbuie
Copy link
Member Author

gadenbuie commented Sep 28, 2020

Fixes #134

@schloerke
Copy link
Collaborator

Thank you!

R/grade_learnr.R Outdated Show resolved Hide resolved
Merge branch 'master' into syntax-scaffold-parse-error

# Conflicts:
#	R/grade_learnr.R
#	tests/testthat/test_zzzz-grade_learnr.R
@gadenbuie
Copy link
Member Author

@schloerke @garrettgman this is ready for re-review.

In short, this PR adds grade_parse_error() an internal function that demonstrates how parse errors can be handled via the exercise.parse.error option. The option accepts a function with a single argument.

The only argument to the parse error function is the gradethis check environment, typically called check_obj, which provides access to everything gradethis knows about the exercise. Most relevant are .user_code and .error which provide a character string of the user-entered code and the error condition thrown from the parse failure. (These are elements in check_obj and are accessed via check_obj$.user_code.)

Finally, the parse error function should return a fail() (or a `pass() if you want) with an appropriate message.

Copy link
Collaborator

@schloerke schloerke left a comment

Choose a reason for hiding this comment

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

LGTM given small changes!

tests/testthat/test_zzzz-grade_learnr.R Outdated Show resolved Hide resolved
R/grade_learnr.R Outdated Show resolved Hide resolved
gadenbuie and others added 2 commits December 4, 2020 14:22
Co-authored-by: Barret Schloerke <barret@rstudio.com>
Co-authored-by: Barret Schloerke <barret@rstudio.com>
@gadenbuie gadenbuie merged commit b11de12 into rstudio:master Dec 8, 2020
@gadenbuie gadenbuie deleted the syntax-scaffold-parse-error branch December 8, 2020 17:26
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.

Default feedback for "fill in the blanks" blanks left in exercise
2 participants