d1 <- data.frame(
record_id = 1:4,
flag_logical = c(TRUE, TRUE, FALSE, TRUE),
flag_Uppercase = c(4, 6, 8, 2)
)
REDCapR::validate_for_write(d = d1)
REDCapR::validate_for_write(d = d1, convert_logical_to_integer = TRUE)
# If `d1` is not a data.frame, the remaining validation checks are skipped:
# REDCapR::validate_for_write(as.matrix(mtcars))
# REDCapR::validate_for_write(c(mtcars, iris))
d2 <- tibble::tribble(
~record_id, ~redcap_event_name, ~redcap_repeat_instrument, ~redcap_repeat_instance,
1L, "e1", "i1", 1L,
1L, "e1", "i1", 2L,
1L, "e1", "i1", 3L,
1L, "e1", "i1", 4L,
1L, "e1", "i2", 1L,
1L, "e1", "i2", 2L,
1L, "e1", "i2", 3L,
1L, "e1", "i2", 4L,
2L, "e1", "i1", 1L,
2L, "e1", "i1", 2L,
2L, "e1", "i1", 3L,
2L, "e1", "i1", 4L,
)
validate_uniqueness(d2)
validate_for_write(d2)
d3 <- tibble::tribble(
~record_id, ~redcap_event_name, ~redcap_repeat_instrument, ~redcap_repeat_instance,
1L, "e1", "i1", 1L,
1L, "e1", "i1", 3L,
1L, "e1", "i1", 3L, # Notice this duplicates the row above
)
# validate_uniqueness(d3)
# Throws error:
# validate_uniqueness(d3, stop_on_error = TRUE)
Run the code above in your browser using DataLab