grade_code: Grade student code against a solution (Legacy)

View source: R/grade_code.R

grade_codeR Documentation

Grade student code against a solution (Legacy)

Description

[Superseded] Please use grade_this_code().

Usage

grade_code(
  correct = NULL,
  incorrect = NULL,
  ...,
  allow_partial_matching = getOption("gradethis.allow_partial_matching", TRUE),
  glue_correct = getOption("gradethis.glue_correct"),
  glue_incorrect = getOption("gradethis.glue_incorrect"),
  glue_pipe = deprecated(),
  grader_args = deprecated(),
  learnr_args = deprecated()
)

Arguments

correct

A character string to display if the student answer matches a known correct answer.

incorrect

A character string to display if the student answer matches a known incorrect answer.

...

ignored. Should be empty

allow_partial_matching

A logical. If FALSE, the partial matching of argument names is not allowed and e.g. runif(1, mi = 0) will return a message indicating that the full formal name min should be used. The default is set via the gradethis.allow_partial_matching option, or by gradethis_setup().

glue_correct

A glue string that returns the final correct message displayed. Defaults to getOption("gradethis_glue_correct").

glue_incorrect

A glue string that returns the final incorrect message displayed. Defaults to getOption("gradethis_glue_incorrect").

glue_pipe

A glue string that returns the final message displayed when the student uses a pipe, ⁠%>%⁠. Defaults to getOption("gradethis.pipe_warning").

grader_args

A list of parameters passed to grader functions (provided by gradethis_exercise_checker()). This contains:

  • user_quo: Quoted R code submitted by the user. For example rlang::quo(1)

  • solution_quo: (Optional) Quoted solution R code provided by the ⁠*-solution⁠ chunk for an exercise.

learnr_args

A list of all parameters passed to gradethis_exercise_checker() by learnr. See https://rstudio.github.io/learnr/exercises.html#exercise_checking for more details.

Details

Checks the code expression or the code result against a solution.

grade_code() compares student code to a solution (i.e. model code) and describes the first way that the student code differs. If the student code exactly matches the solution, grade_code() returns a customizable success message (correct). If the student code does not match the solution, a customizable incorrect message (incorrect) can also be provided.

grade_code() provides a strict check in that the student code must exactly match the solution. It is not enough for the student code to be equivalent to the solution code (e.g. to return the same result as the solution).

You can provide solution code for grade_code() to use in two ways:

  1. Pass code as a character string or a quoted expression to the solution argument of grade_code()

  2. Make a "-solution" code chunk for the exercise to be checked in a learnr document. There is no need to supply a solution argument for grade_code() if you call it from the "-check" chunk of the same exercise. Likewise, there is no need to supply a student submitted code argument when you call grade_code() from a learnr document (learnr will provide the code that the student submits when it runs grade_code().

For best results, name all arguments provided in the solution code.

Value

a function whose first parameter should be an environment that contains all necessary information to compare the code. The result of the returned function will be a graded() object. An incorrect message will describe the first way that the answer differs, the message will be the content of the glue_pipe argument.

See Also

grade_this_code(), grade_code()

Examples

## Not run: 
gradethis_demo()

## End(Not run)

# This is a manual example, see grading demo for `learnr` tutorial usage
y <- expression(sqrt(log(2)))
z <- expression(sqrt(log(1)))
grade_code(grader_args = list(user_quo = y, solution_quo = z))

rstudio-education/grader documentation built on July 6, 2023, 8:48 a.m.