Test whether one set of variables functionally depend on another set of variables.
expect_depends(vars, on, flt = TRUE, data = get_testdata())
expect_*() functions are mainly called for their side effects. The
expectation signals its result (e.g. "success", "failure"), which is logged
by the current test reporter. In a non-testing
context the expectation will raise an error with class
expectation_failure if it fails.
One set of variables, X, functionally depends on another, Y, if and only if
each value in Y corresponds to exactly one value in X. For instance,
course_topic functionally depend on
course_code corresponds to just one combination of
course topic. That is, if two records have the same
they must have the same
See the wikipedia page for more information.
student_course <- data.frame( student_id = 1:5, course_code = c(1, 2, 1, 3, 4), course_duration = c(12, 12, 12, 12, 12), course_topic = c("Song", "Dance", "Song", "Painting", "Pottery") ) # Check that each `course_code` corresponds to exactly one combination of # `course_duration` and `course_topic` expect_depends( c(course_duration, course_topic), on = course_code, data = student_course )