testwhat (version 4.2.2)

test_object: Test R object existence and value

Description

Test whether a student defined a certain object (correctly)

Usage

test_object(name, eq_condition = "equivalent", eval = TRUE, undefined_msg = NULL, incorrect_msg = NULL)
test_data_frame(name, columns = NULL, eq_condition = "equivalent", undefined_msg = NULL, undefined_cols_msg = NULL, incorrect_msg = NULL)
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)
"check_equal"(state, incorrect_msg = NULL, append = TRUE, eq_condition = "equivalent", ...)
"check_equal"(state, incorrect_msg = NULL, append = TRUE, eq_condition = "equivalent", ...)
"check_equal"(state, incorrect_msg = NULL, append = TRUE, eq_condition = "equivalent", ...)

Arguments

name
name of the object to test.
eq_condition
character string indicating how to compare. See is_equal.
eval
Next to existence, check if the value of the object corresponds between student en solution environment
undefined_msg
Optional feedback message in case the student did not define the object. A meaningful message is automatically generated if not supplied.
incorrect_msg
Custom feedback message in case the student's object is not the same as in the sample solution.
columns
character vector of data frame columns to test
undefined_cols_msg
Custom feedback message if not all specified columns of were found in the student's data frame.
state
the state to start from
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.
...
S3 stuff

Examples

Run this code
## Not run: 
# # Example 1
# x <- mean(1:3, na.rm = TRUE)
# 
# # SCT option 1
# test_object("x")
# 
# # SCT option 2 
# ex() %>% check_object("x") %>% check_equal()
# 
# # Example 2
# x <- mean(1:3, na.rm = TRUE)
# 
# # SCT option 1 to only check existence of x
# test_object("x", eval = FALSE)
# 
# # SCT option 2 to only check existence of x
# ex() %>% check_object("x")
# 
# # Example 3
# df <- data.frame(a = 1:3, b = LETTERS[1:3])
# 
# # SCT option 1 to test column a
# test_data_frame("df", columns = "a")
# 
# # SCT option 2 to test column a
# ex() %>% check_object("df") %>% check_column("a") %>% check_equal()
# 
# # Example 4
# lst <- list(a = 1, b = 2)
# 
# # SCT to test only element b
# ex() %>% check_object("lst") %>% check_element("b") %>% check_equal()
# ## End(Not run)

Run the code above in your browser using DataLab