Run an expression in student and solution environment and compare the result, output or error that is thrown by it.

check_expr(state, expr)

# S3 method for ExprState
check_result(state, error_msg = NULL,
  append = TRUE, ...)

# S3 method for ExprState
check_output(state, error_msg = NULL,
  append = TRUE, ...)

# S3 method for ExprState
check_error(state, no_error_msg = NULL,
  append = TRUE, ...)

# S3 method for ExprResultState
check_equal(state, eq_condition = "equivalent",
  eq_fun = NULL, incorrect_msg = NULL, append = TRUE, ...)

# S3 method for ExprOutputState
check_equal(state, eq_fun = NULL,
  incorrect_msg = NULL, append = TRUE, ...)

# S3 method for ExprErrorState
check_equal(state, eq_fun = NULL,
  incorrect_msg = NULL, append = TRUE, ...)

Arguments

state

state to start from (only for check_ functions)

expr

the expression to run

error_msg

custom message in case the expression throws an error while it shouldn't

append

Whether or not to append the feedback to feedback built in previous states

...

S3 stuff

no_error_msg

custom message in case the expression doesn't throw an error while it should

eq_condition

character string indicating how to compare. See is_equal.

eq_fun

optional argument to specify a custom equality function. The function should take two arguments and always return a single boolean value: TRUE or FALSE.

incorrect_msg

custom message in case the result, output or error of the expression does not correspond with the solution

Examples

if (FALSE) { # Example 1 a <- c(1, 2, 3, 4, 5, 6) # SCT ex() %>% check_expr("a[c(2, 4)]") %>% check_result() %>% check_equal() # Example 2 my_fun <- function() { print('hello') } # SCT ex() %>% check_expr("my_fun()") %>% check_output() %>% check_equal() }