Skip to content

Commit

Permalink
require readr >= 2.0
Browse files Browse the repository at this point in the history
ref #343
there are still some warnings
  • Loading branch information
wibeasley committed Jul 21, 2021
1 parent 96e5be1 commit b1e85c4
Show file tree
Hide file tree
Showing 12 changed files with 75 additions and 45 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Description: Encapsulates functions to streamline calls from R to the REDCap
University. The Application Programming Interface (API) offers an avenue
to access and modify data programmatically, improving the capacity for
literate and reproducible programming.
Version: 0.11.1.9004
Version: 0.11.1.9005
Authors@R: c(person("Will", "Beasley", role = c("aut", "cre"), email =
"[email protected]", comment = c(ORCID = "0000-0002-5613-5006")),
person("David", "Bard", role = "ctb"),
Expand All @@ -30,7 +30,7 @@ Imports:
httr (>= 1.4.0),
magrittr (>= 1.5),
methods,
readr (>= 1.3.1),
readr (>= 2.0),
rlang (>= 0.4),
tibble (>= 2.0),
tidyr (>= 1.0)
Expand Down
4 changes: 2 additions & 2 deletions R/kernel-api.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
#'
#' # Consume the results in a few different ways.
#' kernel$result
#' read.csv(text=kernel$raw_text, stringsAsFactors=FALSE)
#' as.list(read.csv(text=kernel$raw_text, stringsAsFactors=FALSE))
#' read.csv(text=kernel$raw_text)
#' as.list(read.csv(text=kernel$raw_text))

kernel_api <- function(
redcap_uri,
Expand Down
6 changes: 5 additions & 1 deletion R/project-simple.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ populate_project_simple <- function(batch = FALSE) {
# utils::write.csv(returned_object_metadata$data, file="./inst/test-data/project-simple/simple-metadata.csv", row.names=FALSE)

# Read in the data in R's memory from a csv file.
ds_to_write <- readr::read_csv(path_in_simple)
ds_to_write <-
readr::read_csv(
path_in_simple,
show_col_types = FALSE
)
# ds_to_write <- utils::read.csv(file="./inst/test-data/project-simple/simple-data.csv", stringsAsFactors=FALSE)

# Remove the calculated variables.
Expand Down
5 changes: 3 additions & 2 deletions R/redcap-metadata-read.R
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,9 @@ redcap_metadata_read <- function(
# Convert the raw text to a dataset.
ds <-
readr::read_csv(
kernel$raw_text,
col_types = col_types
file = I(kernel$raw_text),
col_types = col_types,
show_col_types = FALSE
),
# Don't print the warning in the try block. Print it below,
# where it's under the control of the caller.
Expand Down
6 changes: 5 additions & 1 deletion R/redcap-read-oneshot-eav.R
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,11 @@ redcap_read_oneshot_eav <- function(
if (kernel$success) {
try (
{
ds_eav <- readr::read_csv(kernel$raw_text)
ds_eav <-
readr::read_csv(
file = I(kernel$raw_text),
show_col_types = FALSE
)

ds_metadata_expanded <-
ds_metadata %>%
Expand Down
8 changes: 6 additions & 2 deletions R/redcap-read-oneshot.R
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,12 @@ redcap_read_oneshot <- function(
try(
# Convert the raw text to a dataset.
ds <-
kernel$raw_text %>%
readr::read_csv(col_types = col_types, guess_max = guess_max) %>%
readr::read_csv(
file = I(kernel$raw_text),
col_types = col_types,
guess_max = guess_max,
show_col_types = FALSE
) %>%
as.data.frame(),

# Don't print the warning in the try block. Print it below,
Expand Down
8 changes: 6 additions & 2 deletions R/redcap-report.R
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,12 @@ redcap_report <- function(
try(
# Convert the raw text to a dataset.
ds <-
kernel$raw_text %>%
readr::read_csv(col_types = col_types, guess_max = guess_max) %>%
readr::read_csv(
file = I(kernel$raw_text),
col_types = col_types,
guess_max = guess_max,
show_col_types = FALSE
) %>%
as.data.frame(),

# Don't print the warning in the try block. Print it below,
Expand Down
5 changes: 3 additions & 2 deletions R/redcap-users-export.R
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,9 @@ redcap_users_export <- function(
try(
{ # readr::spec_csv(kernel$raw_text)
ds_combined <- readr::read_csv(
file = kernel$raw_text,
col_types = col_types
file = I(kernel$raw_text),
col_types = col_types,
show_col_types = FALSE
)

# Remove the readr's `spec` attribute about the column names & types.
Expand Down
6 changes: 5 additions & 1 deletion R/redcap-variables.R
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ redcap_variables <- function(
if (kernel$success) {
try(
{
ds <- readr::read_csv(file = kernel$raw_text)
ds <-
readr::read_csv(
file = I(kernel$raw_text),
show_col_types = FALSE
)
}, #Convert the raw text to a dataset.
silent = TRUE
# Don't print the warning in the try block. Print it below, where
Expand Down
7 changes: 4 additions & 3 deletions R/retrieve-credential.R
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,10 @@ retrieve_credential_local <- function(
)

ds_credentials <- readr::read_csv(
file = path_credential,
col_types = col_types,
comment = "#"
file = path_credential,
col_types = col_types,
comment = "#",
show_col_types = FALSE
)

# Check that it's a data.frame with valid variable names
Expand Down
7 changes: 6 additions & 1 deletion tests/testthat/test-metadata-write.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ path_in <- system.file(
"test-data/project-simple/simple-metadata.csv",
package = "REDCapR"
)
dictionary_to_write <- readr::read_csv(path_in, col_types = readr::cols(.default = readr::col_character()))
dictionary_to_write <-
readr::read_csv(
file = path_in,
col_types = readr::cols(.default = readr::col_character()),
show_col_types = FALSE
)

test_that("Metadata Write", {
testthat::skip_on_cran()
Expand Down
54 changes: 28 additions & 26 deletions tests/testthat/test-read-oneshot.R
Original file line number Diff line number Diff line change
Expand Up @@ -204,32 +204,33 @@ test_that("label", {
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/read-oneshot/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 makethe columns unique
# test_that("label-header", {
# testthat::skip_on_cran()
# path_expected <- "test-data/specific-redcapr/read-oneshot/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/read-oneshot/export_checkbox_label.R"
Expand Down Expand Up @@ -348,3 +349,4 @@ test_that("bad token -Error", {
testthat::expect_equal(returned_object$raw_text, "ERROR: You do not have permissions to use the API")
})
rm(credential)

0 comments on commit b1e85c4

Please sign in to comment.