View source: R/check-function.R
| check_function | R Documentation | 
Check whether a student called a function correctly. Note:
test_function and test_function_v2 are now identical and either
can be used.
check_function(state, name, index = 1, not_called_msg = NULL, append = TRUE) check_operator(state, name, index = 1, append = TRUE, not_called_msg = NULL) check_arg(state, arg, arg_not_specified_msg = NULL, append = TRUE) ## S3 method for class 'ArgumentState' check_equal(state, incorrect_msg = NULL, eval = TRUE, eq_condition = "equivalent", eq_fun = NULL, append = TRUE, ...)
| state | state to start from | 
| name | name of the function/operator as a string, e.g.  | 
| index | integer that specifies which call of  | 
| not_called_msg | custom feedback message in case the student did not call the function often enough. | 
| append | Whether or not to append the feedback to feedback built in previous states | 
| arg | name or position of argument to specify
... Arguments can be accessed using '..<INDEX>' (see example 5) (for  | 
| arg_not_specified_msg | custom message in case argument was not
specified (for  | 
| incorrect_msg | custom feedback message in case the student did not call
the function with the same argument values as in the sample solution. You
can specify a vector of arguments with the same length as  | 
| eval | logical vector indicating whether and how to compare arguments.
If  | 
| eq_condition | character vector indicating how to perform the
comparison for each argument. See  | 
| eq_fun | optional argument to specify a custom equality function. The
function should take two arguments and always return a single boolean
value:  | 
| ... | S3 stuff | 
## Not run: 
# Example 1
mean(1:3)
# SCT
ex() %>% check_function("mean") %>% check_arg("x") %>% check_equal()
# Example 2
mean(c(NA, 1, 2), na.rm = TRUE)
# SCT
ex() %>% check_function("mean") %>% {
  check_arg(., "x") %>% check_equal()
  check_arg(., "na.rm") %>% check_equal()
}
# Example 3
5 + 4
# SCT
ex() %>% check_operator("+") %>% check_result() %>% check_equal()
# Example 4: Positional argument check
cor(rnorm(10), rnorm(10))
# SCT
ex() %>% check_function("cor") %>% {
  check_arg(., 1) %>% check_equal()
  check_arg(., 2) %>% check_equal()
}
# Example 5: ... in check_args
soln <- "std_dev <- purrr::compose(sqrt, var, .dir='forward')"
state <- setup_state(soln, soln)
state %>% check_function(., "compose") %>% {
  check_arg(., '..1') %>% check_equal() # sqrt
  check_arg(., '..2') %>% check_equal() # var
  check_arg(., '.dir') %>% check_equal()
}
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.