[1] "expect_condition" "expect_cpp_tests_pass"
[3] "expect_equal" "expect_equal_to_reference"
[5] "expect_equivalent" "expect_error"
[7] "expect_failure" "expect_false"
[9] "expect_gt" "expect_gte"
[11] "expect_identical" "expect_invisible"
[13] "expect_is" "expect_known_hash"
[15] "expect_known_output" "expect_known_value"
[17] "expect_length" "expect_less_than"
[19] "expect_lt" "expect_lte"
[21] "expect_mapequal" "expect_match"
[23] "expect_message" "expect_more_than"
[25] "expect_named" "expect_no_condition"
[27] "expect_no_error" "expect_no_match"
[29] "expect_no_message" "expect_no_warning"
[31] "expect_null" "expect_output"
[33] "expect_output_file" "expect_reference"
[35] "expect_s3_class" "expect_s4_class"
[37] "expect_setequal" "expect_silent"
[39] "expect_snapshot" "expect_snapshot_error"
[41] "expect_snapshot_file" "expect_snapshot_output"
[43] "expect_snapshot_value" "expect_snapshot_warning"
[45] "expect_success" "expect_that"
[47] "expect_true" "expect_type"
[49] "expect_vector" "expect_visible"
[51] "expect_warning"
Bonus
If you are already done all the previous exercises and we have extra time, - or on your own after the workshop, try these additional exercises.
{testthat}
testthat
is one of the main R packages for testing functions (specifically designed for R packages).
Briefly, the approach is to write test scripts that have a series of expectations for the functions. For example, does the function return a particular class or does the function return an error when expected?
See the reference and vignettes here: https://testthat.r-lib.org/
Iteration
Try iterating functions over lists or groups using the apply
family or purrr::map
family.
Object-oriented programming
Read about object-oriented programming classes in R:
Lexical scoping
Try the lexical scoping exercises here: