Skip to content

Commit

Permalink
guess_max allows Inf values
Browse files Browse the repository at this point in the history
close #392
  • Loading branch information
wibeasley committed Aug 14, 2022
1 parent 63cd687 commit 0419b2b
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 13 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Upcoming Release
### Minor Enhancements

* Better documentation for the server url (suggested by @sutzig #395)
* `read_read_oneshot()`'s parameter `guess_max` now allows floating point values to support `readr::read_csv()` ability to accept a Inf value. (Suggested by @eveyp, #392)

Version 1.1.0 (released 2022-08-10)
==========================================================
Expand Down
2 changes: 1 addition & 1 deletion R/redcap-project.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ redcap_project <- setRefClass(
filter_logic = "",

guess_type = TRUE,
guess_max = 1000L,
guess_max = 1000,
verbose = TRUE,
config_options = NULL
) {
Expand Down
2 changes: 1 addition & 1 deletion R/redcap-read-oneshot-eav.R
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ redcap_read_oneshot_eav <- function(
checkmate::assert_logical( blank_for_gray_form_status , any.missing=FALSE, len=1)

# placeholder: checkmate::assert_logical( guess_type , any.missing=FALSE, len=1)
# placeholder: checkmate::assert_integerish(guess_max , any.missing=FALSE, len=1, lower=1)
# placeholder: checkmate::assert_numeric( guess_max , any.missing=FALSE, len=1, lower=1)
checkmate::assert_logical( verbose , any.missing=FALSE, len=1, null.ok=TRUE)
checkmate::assert_list( config_options , any.missing=TRUE , null.ok=TRUE)

Expand Down
7 changes: 4 additions & 3 deletions R/redcap-read-oneshot.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@
#' @param guess_type A boolean value indicating if all columns should be
#' returned as character. If false, [readr::read_csv()] guesses the intended
#' data type for each column. Ignored if `col_types` is not null.
#' @param guess_max A positive integer passed to [readr::read_csv()] that
#' @param guess_max A positive [base::numeric] value
#' passed to [readr::read_csv()] that
#' specifies the maximum number of records to use for guessing column types.
#' @param http_response_encoding The encoding value passed to
#' [httr::content()]. Defaults to 'UTF-8'.
Expand Down Expand Up @@ -192,7 +193,7 @@ redcap_read_oneshot <- function(

col_types = NULL,
guess_type = TRUE,
guess_max = 1000L,
guess_max = 1000,
http_response_encoding = "UTF-8",
locale = readr::default_locale(),
verbose = TRUE,
Expand Down Expand Up @@ -223,7 +224,7 @@ redcap_read_oneshot <- function(
checkmate::assert_logical( blank_for_gray_form_status , any.missing=FALSE, len=1)

checkmate::assert_logical( guess_type , any.missing=FALSE, len=1)
checkmate::assert_integerish(guess_max , any.missing=FALSE, len=1, lower=1)
checkmate::assert_numeric( guess_max , any.missing=FALSE, len=1, lower=1)
checkmate::assert_character(http_response_encoding , any.missing=FALSE, len=1)

checkmate::assert_class( locale, "locale" , null.ok = FALSE)
Expand Down
7 changes: 4 additions & 3 deletions R/redcap-report.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
#' @param guess_type A boolean value indicating if all columns should be
#' returned as character. If false, [readr::read_csv()] guesses the intended
#' data type for each column. Ignored if `col_types` is not null.
#' @param guess_max A positive integer passed to [readr::read_csv()] that
#' @param guess_max A positive [base::numeric] value
#' passed to [readr::read_csv()] that
#' specifies the maximum number of records to use for guessing column types.
#' @param verbose A boolean value indicating if `message`s should be printed
#' to the R console during the operation. The verbose output might contain
Expand Down Expand Up @@ -127,7 +128,7 @@ redcap_report <- function(

col_types = NULL,
guess_type = TRUE,
guess_max = 1000L,
guess_max = 1000,
verbose = TRUE,
config_options = NULL
) {
Expand All @@ -142,7 +143,7 @@ redcap_report <- function(
checkmate::assert_logical( export_checkbox_label , any.missing=FALSE, len=1)

checkmate::assert_logical( guess_type , any.missing=FALSE, len=1)
checkmate::assert_integerish(guess_max , any.missing=FALSE, len=1, lower=1)
checkmate::assert_numeric( guess_max , any.missing=FALSE, len=1, lower=1)
checkmate::assert_logical( verbose , any.missing=FALSE, len=1, null.ok=TRUE)
checkmate::assert_list( config_options , any.missing=TRUE , null.ok=TRUE)

Expand Down
2 changes: 1 addition & 1 deletion man/redcap_project.Rd

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

5 changes: 3 additions & 2 deletions man/redcap_read_oneshot.Rd

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

5 changes: 3 additions & 2 deletions man/redcap_report.Rd

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

26 changes: 26 additions & 0 deletions tests/testthat/test-read-oneshot.R
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,32 @@ test_that("date-range", {
expect_true(returned_object$success)
})

test_that("guess_max-Inf", {
testthat::skip_on_cran()
expected_outcome_message <- "\\d+ records and \\d+ columns were read from REDCap in \\d+(\\.\\d+\\W|\\W)seconds\\."

expect_message(
regexp = expected_outcome_message,
returned_object <- redcap_read_oneshot(
redcap_uri = credential$redcap_uri,
token = credential$token,
guess_max = Inf
)
)

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

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("bad token -Error", {
testthat::skip_on_cran()
expected_outcome_message <- "The REDCapR read/export operation was not successful\\."
Expand Down

0 comments on commit 0419b2b

Please sign in to comment.