Check that the roxygen comments provided by the student are correct.

check_has_roxy(state, index = 1L, missing_msg = NULL, append = TRUE)

check_has_roxy_element(state, element, index = 1L, missing_msg = NULL,
  append = TRUE)

check_roxy_element_equals(state, element, index = 1L,
  incorrect_msg = NULL, append = TRUE)

check_roxy_element_matches(state, element, regex, fixed = FALSE,
  times = 1L, index = 1L, not_typed_msg = NULL, append = TRUE)

check_has_roxy_param(state, param_name, index = 1L, missing_msg = NULL,
  append = TRUE)

check_roxy_param_matches(state, param_name, regex, fixed = FALSE,
  index = 1L, not_typed_msg = NULL, append = TRUE)

check_roxy_imports_package(state, pkg_name, index = 1L, missing_msg = NULL,
  append = TRUE)

check_roxy_imports_from_package(state, pkg_name, index = 1L,
  missing_msg = NULL, append = TRUE)

check_roxy_imports_object_from_package(state, pkg_name, object_name,
  index = 1L, missing_msg = NULL, append = TRUE)

check_roxy_examples_run(state, index = 1L, not_runnable_msg = NULL,
  append = TRUE)

check_roxy_examples_result_equals(state, index = 1L,
  incorrect_msg = NULL, append = TRUE)

check_roxy_example_matches(state, regex, fixed = FALSE, index = 1L,
  not_typed_msg = NULL, append = TRUE)

Arguments

state

The state of the exercise, as returned from parse_roxy.

index

A positive integer or a string naming a function. This describes which roxygen element in the code to check.

missing_msg

Optional string. Used to override the feedback message in the event of failure.

append

For compatibility; currently unused.

element

String naming the element of the roxygen block to check.

incorrect_msg

Optional string. Used to override the feedback message in the event of failure.

regex

String providing a regular expression for the solution code to match. See See testwhat's check_code function.

fixed

Logical. If TRUE, regex is treated as a fixed string, not a regular expression. See testwhat's check_code function.

times

Positive integer. Denotes the number of times the string in regex should be matched.

not_typed_msg

Optional string. Used to override the feedback message in the event of failure.

param_name

String naming a parameter for the function.

pkg_name

String naming an R package to import from.

object_name

String naming an object to import from another package.

not_runnable_msg

Optional string. Used to override the feedback message in the event of failure. incorrect_msg

Value

This function is invoked for the side effect of registering feedback in the event of a failed test. See check_that for details of the return value and feedback mechanism.

Details

check_has_roxy checks that the index block of roxygen is present. check_has_roxy_element checks that the element element of the index block of roxygen is present. check_roxy_element_equals checks that the element element of the index block of roxygen is equal to the value in the solution code. check_roxy_element_matches checks that the element element of the index block of roxygen matches a regular expression or string. check_roxy_param_equals checks that the param_name parameter of the index block of roxygen is equal to the value in the solution code. check_roxy_param_matches checks that the param_name element of the index block of roxygen matches a regular expression or string. check_roxy_example_results checks that the final result of running the examples in the index block of roxygen is equal to the value in the solution code. check_roxy_example_matches check that the examples of the index block of roxygen matches a regular expression or string.

Only check_roxy_element_equals and check_roxy_example_results require the solution. The other checks can safely be run with '___BLOCK_SOLUTION_EXEC___'.

Examples

# NOT RUN {
  # Always begin by calling parse_roxy() on the exercise state.
  ex() %>% parse_roxy() %>% {
    check_has_roxy(.)
    check_has_roxy_element(., 'title')
    check_roxy_element_equals(., 'description', 'This is a mean function')
    check_roxy_element_matches(., 'return', 'integer +vector')
    check_roxy_param_equals(., 'x', 'A numeric vector.')
    check_roxy_param_matches(., 'na.rm', '[Ll]ogical.*missing.')
    check_roxy_example_results(., 10)
    check_roxy_example_matches(., 'mean\\\\(.*\\\\)')
  }
# }