Check whether a student defined a certain object (correctly)

check_object(state, name, undefined_msg = NULL, append = TRUE)

check_column(state, col, col_missing_msg = NULL, append = TRUE)

check_element(state, el, el_missing_msg = NULL, append = TRUE)

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

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

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

Arguments

state

the state to start from

name

name of the object to test.

undefined_msg

Optional feedback message in case the student did not define the object. A meaningful message is automatically generated if not supplied.

append

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

col

name of column to check

col_missing_msg

Custom message in case data frame column is missing

el

name of element to check

el_missing_msg

Custom message in case element is messing.

incorrect_msg

Custom feedback message in case the student's object is not the same as in the sample solution.

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.

...

S3 stuff

Examples

if (FALSE) { # Example 1 x <- mean(1:3, na.rm = TRUE) # sct to only check existence of x ex() %>% check_object("x") # sct to check existence and equality ex() %>% check_object("x") %>% check_equal() # Example 2 df <- data.frame(a = 1:3, b = LETTERS[1:3]) # sct to test column a ex() %>% check_object("df") %>% check_column("a") %>% check_equal() # Example 3 lst <- list(a = 1, b = 2) # sct to test only element b ex() %>% check_object("lst") %>% check_element("b") %>% check_equal() # Example 4 today <- Sys.Date() # sct to check if classes are equal ex() %>% check_object("today") %>% check_equal(eq_fun = function(x, y) { all.equal(class(x), class(y)) }) }