Test whether one set of variables functionally depend on another set of variables.

expect_depends(vars, on, flt = TRUE, data = get_testdata())



<tidy-select> A set of columns to test.


<tidy-select> A set of columns which vars are expected to depend on.


<data-masking> A filter specifying a subset of the data frame to test.


A data frame to test. The global test data is used by default.


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_duration and course_topic functionally depend on course_code if each course_code corresponds to just one combination of course_duration and course topic. That is, if two records have the same course_code then they must have the same course_duration and course_topic.

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`
  c(course_duration, course_topic),
  on = course_code,
  data = student_course