Skip to content

Commit

Permalink
new http_response_encoding parameter for reading records
Browse files Browse the repository at this point in the history
closes #354

cc: @lrasmus
  • Loading branch information
wibeasley committed Nov 7, 2021
1 parent b290c14 commit 67e95d6
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 2 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Upcoming Versions
* `redcap_metadata_read()` now uses json (instead of csv) to transfer the dictionary between server & client. This accommodates super-wide dictionaries with 35k+ variables. The user shouldn't notice a difference, and still will receive a data.frame. (#335, @januz & @datalorax)
* Include a few more `testthat::skip_on_cran()` calls to comply with CRAN's ["fail gracefully"](https://cran.r-project.org/web/packages/policies.html) policy. Similarly, skip remaining examples that depend on external resources. (#352)
* `retrieve_credential_local()` can now user `username` to identify the desired credential row (#364)
* `redcap_read()` and `redcap_read_oneshot()` gain the `http_response_encoding` parameter that's passed to [`httr::content()`](https://httr.r-lib.org/reference/content.html). The default value remains "UTF-8". (#354, @lrasmus)

### Test Suite

Expand Down
12 changes: 11 additions & 1 deletion R/redcap-read-oneshot.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
#' data type for each column. Ignored if `col_types` is not null.
#' @param guess_max A positive integer 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'.
#' @param verbose A boolean value indicating if `message`s should be printed
#' to the R console during the operation. The verbose output might contain
#' sensitive information (*e.g.* PHI), so turn this off if the output might
Expand Down Expand Up @@ -177,6 +179,7 @@ redcap_read_oneshot <- function(
col_types = NULL,
guess_type = TRUE,
guess_max = 1000L,
http_response_encoding = "UTF-8",
verbose = TRUE,
config_options = NULL
) {
Expand Down Expand Up @@ -205,6 +208,8 @@ redcap_read_oneshot <- function(

checkmate::assert_logical( guess_type , any.missing=FALSE, len=1)
checkmate::assert_integerish(guess_max , any.missing=FALSE, len=1, lower=1)
checkmate::assert_character(http_response_encoding , any.missing=FALSE, len=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 Expand Up @@ -246,7 +251,12 @@ redcap_read_oneshot <- function(
if (0L < nchar(events_collapsed )) post_body$events <- events_collapsed

# This is the important line that communicates with the REDCap server.
kernel <- kernel_api(redcap_uri, post_body, config_options)
kernel <- kernel_api(
redcap_uri = redcap_uri,
post_body = post_body,
config_options = config_options,
encoding = http_response_encoding
)

if (kernel$success) {
col_types <-
Expand Down
9 changes: 8 additions & 1 deletion R/redcap-read.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@
#' returned as character. If true, [readr::read_csv()] guesses the intended
#' data type for each column.
#' @param guess_max Deprecated.
#' @param http_response_encoding The encoding value passed to
#' [httr::content()]. Defaults to 'UTF-8'.
#' @param verbose A boolean value indicating if `message`s should be printed
#' to the R console during the operation. The verbose output might contain
#' sensitive information (*e.g.* PHI), so turn this off if the output might
Expand Down Expand Up @@ -190,6 +192,7 @@ redcap_read <- function(
col_types = NULL,
guess_type = TRUE,
guess_max = NULL, # Deprecated parameter
http_response_encoding = "UTF-8",
verbose = TRUE,
config_options = NULL,
id_position = 1L
Expand Down Expand Up @@ -217,8 +220,10 @@ redcap_read <- function(
checkmate::assert_posixct( datetime_range_end , any.missing=TRUE , len=1, null.ok=TRUE)

checkmate::assert_logical( guess_type , any.missing=FALSE, len=1)

if (!is.null(guess_max)) warning("The `guess_max` parameter in `REDCapR::redcap_read()` is deprecated.")

checkmate::assert_character(http_response_encoding , any.missing=FALSE, len=1)

checkmate::assert_logical( verbose , any.missing=FALSE, len=1, null.ok=TRUE)
checkmate::assert_list( config_options , any.missing=TRUE , null.ok=TRUE)
checkmate::assert_integer( id_position , any.missing=FALSE, len=1, lower=1L)
Expand Down Expand Up @@ -264,6 +269,7 @@ redcap_read <- function(
datetime_range_begin = datetime_range_begin,
datetime_range_end = datetime_range_end,
guess_type = guess_type,
http_response_encoding = http_response_encoding,
verbose = verbose,
config_options = config_options
)
Expand Down Expand Up @@ -334,6 +340,7 @@ redcap_read <- function(
col_types = col_types,
guess_type = FALSE,
# guess_max = guess_max, # Not used, because guess_type is FALSE
http_response_encoding = http_response_encoding,
verbose = verbose,
config_options = config_options
)
Expand Down
4 changes: 4 additions & 0 deletions man/redcap_read.Rd

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

4 changes: 4 additions & 0 deletions man/redcap_read_oneshot.Rd

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

0 comments on commit 67e95d6

Please sign in to comment.