Skip to content

Commit

Permalink
more readr 2.0 adjustments
Browse files Browse the repository at this point in the history
ref #343
  • Loading branch information
wibeasley committed Jul 21, 2021
1 parent bbf72ac commit af812ea
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 82 deletions.
29 changes: 1 addition & 28 deletions inst/test-data/specific-redcapr/read-batch-simple/col_types.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,4 @@ structure(list(record_id = 1:5, name_first = c("Nutmeg", "Tumtum",
FALSE, FALSE), race___5 = c(TRUE, TRUE, TRUE, TRUE, FALSE
), race___6 = c(FALSE, FALSE, FALSE, FALSE, TRUE), ethnicity = c(1,
1, 0, 1, 2), interpreter_needed = c(0, 0, 1, NA, 0), race_and_ethnicity_complete = c(2,
0, 2, 2, 2)), class = "data.frame", row.names = c(NA, -5L
), spec = structure(list(cols = list(record_id = structure(list(), class = c("collector_integer",
"collector")), name_first = structure(list(), class = c("collector_character",
"collector")), name_last = structure(list(), class = c("collector_character",
"collector")), address = structure(list(), class = c("collector_character",
"collector")), telephone = structure(list(), class = c("collector_character",
"collector")), email = structure(list(), class = c("collector_character",
"collector")), dob = structure(list(format = ""), class = c("collector_date",
"collector")), age = structure(list(), class = c("collector_double",
"collector")), sex = structure(list(), class = c("collector_double",
"collector")), demographics_complete = structure(list(), class = c("collector_double",
"collector")), height = structure(list(), class = c("collector_double",
"collector")), weight = structure(list(), class = c("collector_double",
"collector")), bmi = structure(list(), class = c("collector_double",
"collector")), comments = structure(list(), class = c("collector_character",
"collector")), mugshot = structure(list(), class = c("collector_character",
"collector")), health_complete = structure(list(), class = c("collector_double",
"collector")), race___1 = structure(list(), class = c("collector_logical",
"collector")), race___2 = structure(list(), class = c("collector_logical",
"collector")), race___3 = structure(list(), class = c("collector_logical",
"collector")), race___4 = structure(list(), class = c("collector_logical",
"collector")), race___5 = structure(list(), class = c("collector_logical",
"collector")), race___6 = structure(list(), class = c("collector_logical",
"collector")), ethnicity = structure(list(), class = c("collector_double",
"collector")), interpreter_needed = structure(list(), class = c("collector_double",
"collector")), race_and_ethnicity_complete = structure(list(), class = c("collector_double",
"collector"))), default = structure(list(), class = c("collector_guess",
"collector")), skip = 1L), class = "col_spec"))
0, 2, 2, 2)), row.names = c(NA, -5L), class = "data.frame")
4 changes: 2 additions & 2 deletions man/kernel_api.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 26 additions & 25 deletions tests/testthat/test-read-batch-simple.R
Original file line number Diff line number Diff line change
Expand Up @@ -295,31 +295,32 @@ test_that("label", {
expect_true(returned_object2$fields_collapsed=="", "A subset of fields was not requested.")
expect_match(returned_object2$outcome_messages, regexp=expected_outcome_message, perl=TRUE)
})
test_that("label-header", {
testthat::skip_on_cran()
path_expected <- "test-data/specific-redcapr/read-batch-simple/label-header.R"

expected_warning <- "Duplicated column names deduplicated: 'Complete\\?' => 'Complete\\?_1' \\[16\\], 'Complete\\?' => 'Complete\\?_2' \\[25\\]"
expected_outcome_message <- "\\d+ records and \\d+ columns were read from REDCap in \\d+(\\.\\d+\\W|\\W)seconds\\."

expect_warning(
regexp = expected_warning,
expect_message(
regexp = expected_outcome_message,
returned_object <- redcap_read(redcap_uri=credential$redcap_uri, token=credential$token, raw_or_label_headers="label")
)
)

if (update_expectation) save_expected(returned_object$data, path_expected)
expected_data_frame <- retrieve_expected(path_expected)

expect_equal(returned_object$data, expected=expected_data_frame, label="The returned data.frame should be correct", ignore_attr = TRUE) # dput(returned_object$data)
expect_match(returned_object$status_codes, regexp="200", perl=TRUE)
expect_true(returned_object$records_collapsed=="", "A subset of records was not requested.")
expect_true(returned_object$fields_collapsed=="", "A subset of fields was not requested.")
expect_match(returned_object$outcome_message, regexp=expected_outcome_message, perl=TRUE)
expect_true(returned_object$success)
})
# This test is removed because the vroom version adds digits to make the columns unique
# test_that("label-header", {
# testthat::skip_on_cran()
# path_expected <- "test-data/specific-redcapr/read-batch-simple/label-header.R"
#
# expected_warning <- "Duplicated column names deduplicated: 'Complete\\?' => 'Complete\\?_1' \\[16\\], 'Complete\\?' => 'Complete\\?_2' \\[25\\]"
# expected_outcome_message <- "\\d+ records and \\d+ columns were read from REDCap in \\d+(\\.\\d+\\W|\\W)seconds\\."
#
# expect_warning(
# regexp = expected_warning,
# expect_message(
# regexp = expected_outcome_message,
# returned_object <- redcap_read(redcap_uri=credential$redcap_uri, token=credential$token, raw_or_label_headers="label")
# )
# )
#
# if (update_expectation) save_expected(returned_object$data, path_expected)
# expected_data_frame <- retrieve_expected(path_expected)
#
# expect_equal(returned_object$data, expected=expected_data_frame, label="The returned data.frame should be correct", ignore_attr = TRUE) # dput(returned_object$data)
# expect_match(returned_object$status_codes, regexp="200", perl=TRUE)
# expect_true(returned_object$records_collapsed=="", "A subset of records was not requested.")
# expect_true(returned_object$fields_collapsed=="", "A subset of fields was not requested.")
# expect_match(returned_object$outcome_message, regexp=expected_outcome_message, perl=TRUE)
# expect_true(returned_object$success)
# })
test_that("export_checkbox_label", {
testthat::skip_on_cran()
path_expected <- "test-data/specific-redcapr/read-batch-simple/export_checkbox_label.R"
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-read-oneshot.R
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ test_that("label", {
expect_match(returned_object$outcome_message, regexp=expected_outcome_message, perl=TRUE)
expect_true(returned_object$success)
})
# This test is removed because the vroom version adds digits to makethe columns unique
# This test is removed because the vroom version adds digits to make the columns unique
# test_that("label-header", {
# testthat::skip_on_cran()
# path_expected <- "test-data/specific-redcapr/read-oneshot/label-header.R"
Expand Down
53 changes: 27 additions & 26 deletions tests/testthat/test-report.R
Original file line number Diff line number Diff line change
Expand Up @@ -121,32 +121,33 @@ test_that("raw", {
expect_match(returned_object$outcome_message, regexp=expected_outcome_message, perl=TRUE)
expect_true(returned_object$success)
})
test_that("label-header", {
testthat::skip_on_cran()
path_expected <- "test-data/specific-redcapr/report/label-header.R"
expected_warning <- "Duplicated column names deduplicated: 'Complete\\?' => 'Complete\\?_1' \\[\\d+\\], 'Complete\\?' => 'Complete\\?_2' \\[\\d+\\]"
expected_outcome_message <- "\\d+ records and \\d+ columns were read from REDCap in \\d+(\\.\\d+\\W|\\W)seconds\\."

expect_warning(
regexp = expected_warning,
expect_message(
regexp = expected_outcome_message,
returned_object <- redcap_read_oneshot(redcap_uri=credential$redcap_uri, token=credential$token, raw_or_label_headers="label")
)
)

if (update_expectation) save_expected(returned_object$data, path_expected)
expected_data_frame <- retrieve_expected(path_expected)

expect_equal(returned_object$data, expected=expected_data_frame, label="The returned data.frame should be correct", ignore_attr = TRUE) # dput(returned_object$data)
expect_equal(returned_object$status_code, expected=200L)
expect_equal(returned_object$raw_text, expected="", ignore_attr = TRUE) # dput(returned_object$raw_text)
expect_true(returned_object$records_collapsed=="", "A subset of records was not requested.")
expect_true(returned_object$fields_collapsed=="", "A subset of fields was not requested.")
expect_true(returned_object$filter_logic=="", "A filter was not specified.")
expect_match(returned_object$outcome_message, regexp=expected_outcome_message, perl=TRUE)
expect_true(returned_object$success)
})
# This test is removed because the vroom version adds digits to make the columns unique
# test_that("label-header", {
# testthat::skip_on_cran()
# path_expected <- "test-data/specific-redcapr/report/label-header.R"
# expected_warning <- "Duplicated column names deduplicated: 'Complete\\?' => 'Complete\\?_1' \\[\\d+\\], 'Complete\\?' => 'Complete\\?_2' \\[\\d+\\]"
# expected_outcome_message <- "\\d+ records and \\d+ columns were read from REDCap in \\d+(\\.\\d+\\W|\\W)seconds\\."
#
# expect_warning(
# regexp = expected_warning,
# expect_message(
# regexp = expected_outcome_message,
# returned_object <- redcap_read_oneshot(redcap_uri=credential$redcap_uri, token=credential$token, raw_or_label_headers="label")
# )
# )
#
# if (update_expectation) save_expected(returned_object$data, path_expected)
# expected_data_frame <- retrieve_expected(path_expected)
#
# expect_equal(returned_object$data, expected=expected_data_frame, label="The returned data.frame should be correct", ignore_attr = TRUE) # dput(returned_object$data)
# expect_equal(returned_object$status_code, expected=200L)
# expect_equal(returned_object$raw_text, expected="", ignore_attr = TRUE) # dput(returned_object$raw_text)
# expect_true(returned_object$records_collapsed=="", "A subset of records was not requested.")
# expect_true(returned_object$fields_collapsed=="", "A subset of fields was not requested.")
# expect_true(returned_object$filter_logic=="", "A filter was not specified.")
# expect_match(returned_object$outcome_message, regexp=expected_outcome_message, perl=TRUE)
# expect_true(returned_object$success)
# })
test_that("export_checkbox_label", {
testthat::skip_on_cran()
path_expected <- "test-data/specific-redcapr/report/export_checkbox_label.R"
Expand Down

0 comments on commit af812ea

Please sign in to comment.