Skip to content

Commit 2c374a6

Browse files
committed
handle for the rest of the function
ref #429
1 parent 4bd5bd8 commit 2c374a6

30 files changed

+304
-65
lines changed

NEWS.md

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ These features are not yet on CRAN. Install with `remotes::install_github(repo
2626
* New `redcap_log_read()` function. Exports a project's log. (Thanks @joundso, #383, #320)
2727
* New `redcap_project_info_read()` function. Exports a project's information, such as its language and production status. (Thanks @skadauke, #410)
2828
* New parameter `blank_for_gray_form_status` in the functions `redcap_read()`, `redcap_read_oneshot()`, and `redcap_read_oneshot_eav()`. (@greg-botwin, #386, #389)
29+
* A `httr::handle` value is accepted by functions that contact the server. This will accommodate some institutions with unconventional environments. (Suggested by @brandonpotvin, #429)
2930
* `sanitized_token()` now accepts an alternative regex pattern. (Suggested by @maeon & @michalkouril, #370)
3031

3132
### Minor Enhancements

R/redcap-dag-read.R

+17-9
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
#' be visible somewhere public. Optional.
2424
#' @param config_options A list of options passed to [httr::POST()].
2525
#' See details at [httr::httr_options()]. Optional.
26+
#' @param handle_httr The value passed to the `handle` parameter of
27+
#' [httr::POST()].
28+
#' This is useful for only unconventional authentication approaches. It
29+
#' should be `NULL` for most institutions. Optional.
2630
#'
2731
#' @return
2832
#' Currently, a list is returned with the following elements:
@@ -63,8 +67,10 @@ redcap_dag_read <- function(
6367
http_response_encoding = "UTF-8",
6468
locale = readr::default_locale(),
6569
verbose = TRUE,
66-
config_options = NULL
70+
config_options = NULL,
71+
handle_httr = NULL
6772
) {
73+
6874
checkmate::assert_character(redcap_uri , any.missing=FALSE, len=1, pattern="^.{1,}$")
6975
checkmate::assert_character(token , any.missing=FALSE, len=1, pattern="^.{1,}$")
7076
checkmate::assert_character(http_response_encoding , any.missing=FALSE, len=1)
@@ -82,13 +88,15 @@ redcap_dag_read <- function(
8288
format = "csv"
8389
)
8490

85-
# This is the important line that communicates with the REDCap server.
86-
kernel <- kernel_api(
87-
redcap_uri = redcap_uri,
88-
post_body = post_body,
89-
config_options = config_options,
90-
encoding = http_response_encoding
91-
)
91+
# This is the important call that communicates with the REDCap server.
92+
kernel <-
93+
kernel_api(
94+
redcap_uri = redcap_uri,
95+
post_body = post_body,
96+
encoding = http_response_encoding,
97+
config_options = config_options,
98+
handle_httr = handle_httr
99+
)
92100

93101
if (kernel$success) {
94102
try(
@@ -124,7 +132,7 @@ redcap_dag_read <- function(
124132
kernel$success <- FALSE
125133
ds <- tibble::tibble()
126134
outcome_message <- sprintf(
127-
"The REDCap read failed. The http status code was %i. The 'raw_text' returned was '%s'.",
135+
"The REDCap dag read failed. The http status code was %i. The 'raw_text' returned was '%s'.",
128136
kernel$status_code,
129137
kernel$raw_text
130138
)

R/redcap-download-file-oneshot.R

+13-2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@
3434
#' to the R console during the operation. Optional.
3535
#' @param config_options A list of options passed to [httr::POST()].
3636
#' See details at [httr::httr_options()]. Optional.
37+
#' @param handle_httr The value passed to the `handle` parameter of
38+
#' [httr::POST()].
39+
#' This is useful for only unconventional authentication approaches. It
40+
#' should be `NULL` for most institutions. Optional.
3741
#'
3842
#' @return
3943
#' Currently, a list is returned with the following elements,
@@ -119,7 +123,8 @@ redcap_download_file_oneshot <- function(
119123
repeat_instrument = NULL,
120124
repeat_instance = NULL,
121125
verbose = TRUE,
122-
config_options = NULL
126+
config_options = NULL,
127+
handle_httr = NULL
123128
) {
124129

125130
checkmate::assert_character(file_name , null.ok = TRUE , len=1, pattern="^.{1,}$")
@@ -159,7 +164,13 @@ redcap_download_file_oneshot <- function(
159164

160165
# This is the first of two important lines in the function.
161166
# It retrieves the information from the server and stores it in RAM.
162-
kernel <- kernel_api(redcap_uri, post_body, config_options)
167+
kernel <-
168+
kernel_api(
169+
redcap_uri = redcap_uri,
170+
post_body = post_body,
171+
config_options = config_options,
172+
handle_httr = handle_httr
173+
)
163174

164175
if (kernel$success) {
165176
result_header <- kernel$result_headers$`content-type`

R/redcap-event-instruments.R

+14-3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
#' be visible somewhere public. Optional.
2323
#' @param config_options A list of options passed to [httr::POST()].
2424
#' See details at [httr::httr_options()]. Optional.
25+
#' @param handle_httr The value passed to the `handle` parameter of
26+
#' [httr::POST()].
27+
#' This is useful for only unconventional authentication approaches. It
28+
#' should be `NULL` for most institutions. Optional.
2529
#'
2630
#' @return
2731
#' Currently, a list is returned with the following elements,
@@ -65,7 +69,8 @@ redcap_event_instruments <- function(
6569
token,
6670
arms = c("1"),
6771
verbose = TRUE,
68-
config_options = NULL
72+
config_options = NULL,
73+
handle_httr = NULL
6974
) {
7075

7176
checkmate::assert_character(redcap_uri, any.missing=FALSE, len=1, pattern="^.{1,}$")
@@ -87,8 +92,14 @@ redcap_event_instruments <- function(
8792
form = readr::col_character()
8893
)
8994

90-
# This is the important line that communicates with the REDCap server.
91-
kernel <- kernel_api(redcap_uri, post_body, config_options)
95+
# This is the important call that communicates with the REDCap server.
96+
kernel <-
97+
kernel_api(
98+
redcap_uri = redcap_uri,
99+
post_body = post_body,
100+
config_options = config_options,
101+
handle_httr = handle_httr
102+
)
92103

93104
if (kernel$success) {
94105
try(

R/redcap-instrument-download.R

+13-2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929
#' to the R console during the operation. Optional.
3030
#' @param config_options A list of options passed to [httr::POST()].
3131
#' See details at [httr::httr_options()]. Optional.
32+
#' @param handle_httr The value passed to the `handle` parameter of
33+
#' [httr::POST()].
34+
#' This is useful for only unconventional authentication approaches. It
35+
#' should be `NULL` for most institutions. Optional.
3236
#'
3337
#' @return
3438
#' Currently, a list is returned with the following elements,
@@ -108,7 +112,8 @@ redcap_download_instrument <- function(
108112
instrument = "",
109113
event = "",
110114
verbose = TRUE,
111-
config_options = NULL
115+
config_options = NULL,
116+
handle_httr = NULL
112117
) {
113118

114119
checkmate::assert_character(file_name , null.ok = TRUE , len=1, pattern="^.{1,}$")
@@ -135,7 +140,13 @@ redcap_download_instrument <- function(
135140

136141
# This is the first of two important lines in the function.
137142
# It retrieves the information from the server and stores it in RAM.
138-
kernel <- kernel_api(redcap_uri, post_body, config_options)
143+
kernel <-
144+
kernel_api(
145+
redcap_uri = redcap_uri,
146+
post_body = post_body,
147+
config_options = config_options,
148+
handle_httr = handle_httr
149+
)
139150

140151
if (kernel$success) {
141152
result_header <- kernel$result_headers$`content-type`

R/redcap-instruments.R

+14-3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
#' be visible somewhere public. Optional.
2525
#' @param config_options A list of options passed to [httr::POST()].
2626
#' See details at [httr::httr_options()]. Optional.
27+
#' @param handle_httr The value passed to the `handle` parameter of
28+
#' [httr::POST()].
29+
#' This is useful for only unconventional authentication approaches. It
30+
#' should be `NULL` for most institutions. Optional.
2731
#'
2832
#' @return
2933
#' Currently, a list is returned with the following elements,
@@ -66,7 +70,8 @@ redcap_instruments <- function(
6670
redcap_uri,
6771
token,
6872
verbose = TRUE,
69-
config_options = NULL
73+
config_options = NULL,
74+
handle_httr = NULL
7075
) {
7176

7277
checkmate::assert_character(redcap_uri, any.missing=FALSE, len=1, pattern="^.{1,}$")
@@ -86,8 +91,14 @@ redcap_instruments <- function(
8691
instrument_label = readr::col_character()
8792
)
8893

89-
# This is the important line that communicates with the REDCap server.
90-
kernel <- kernel_api(redcap_uri, post_body, config_options)
94+
# This is the important call that communicates with the REDCap server.
95+
kernel <-
96+
kernel_api(
97+
redcap_uri = redcap_uri,
98+
post_body = post_body,
99+
config_options = config_options,
100+
handle_httr = handle_httr
101+
)
91102

92103
if (kernel$success) {
93104
try(

R/redcap-log-read.R

+9-3
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@
3939
#' be visible somewhere public. Optional.
4040
#' @param config_options A list of options passed to [httr::POST()].
4141
#' See details at [httr::httr_options()]. Optional.
42+
#' @param handle_httr The value passed to the `handle` parameter of
43+
#' [httr::POST()].
44+
#' This is useful for only unconventional authentication approaches. It
45+
#' should be `NULL` for most institutions. Optional.
4246
#'
4347
#' @return
4448
#' Currently, a list is returned with the following elements:
@@ -105,7 +109,8 @@ redcap_log_read <- function(
105109
http_response_encoding = "UTF-8",
106110
locale = readr::default_locale(),
107111
verbose = TRUE,
108-
config_options = NULL
112+
config_options = NULL,
113+
handle_httr = NULL
109114
) {
110115
checkmate::assert_character(redcap_uri , any.missing = FALSE, len = 1, pattern = "^.{1,}$")
111116
checkmate::assert_character(token , any.missing = FALSE, len = 1, pattern = "^.{1,}$")
@@ -134,12 +139,13 @@ redcap_log_read <- function(
134139
user = user
135140
)
136141

137-
# This is the important line that communicates with the REDCap server.
142+
# This is the important call that communicates with the REDCap server.
138143
kernel <- kernel_api(
139144
redcap_uri = redcap_uri,
140145
post_body = post_body,
146+
encoding = http_response_encoding,
141147
config_options = config_options,
142-
encoding = http_response_encoding
148+
handle_httr = handle_httr
143149
)
144150

145151
if (kernel$success) {

R/redcap-metadata-coltypes.R

+10-5
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
#' be visible somewhere public. Optional.
2525
#' @param config_options A list of options passed to [httr::POST()].
2626
#' See details at [httr::httr_options()]. Optional.
27+
#' @param handle_httr The value passed to the `handle` parameter of
28+
#' [httr::POST()].
29+
#' This is useful for only unconventional authentication approaches. It
30+
#' should be `NULL` for most institutions. Optional.
2731
#'
2832
#' @return
2933
#' A [readr::cols()] object is returned, which can be
@@ -152,7 +156,8 @@ redcap_metadata_coltypes <- function(
152156
http_response_encoding = "UTF-8",
153157
locale = readr::default_locale(),
154158
verbose = FALSE,
155-
config_options = NULL
159+
config_options = NULL,
160+
handle_httr = NULL
156161
) {
157162

158163
checkmate::assert_character(redcap_uri , any.missing=FALSE, len=1, pattern="^.{1,}$")
@@ -167,10 +172,10 @@ redcap_metadata_coltypes <- function(
167172
verbose <- verbose_prepare(verbose)
168173

169174
# Retrieve the info necessary to infer the likely data types
170-
d_var <- REDCapR::redcap_variables( redcap_uri, token, verbose = verbose)$data
171-
d_meta <- REDCapR::redcap_metadata_read( redcap_uri, token, verbose = verbose)$data
172-
d_inst <- REDCapR::redcap_instruments( redcap_uri, token, verbose = verbose)$data
173-
d_proj <- REDCapR::redcap_project_info_read(redcap_uri, token, verbose = verbose)$data
175+
d_var <- REDCapR::redcap_variables( redcap_uri, token, verbose = verbose, handle_httr = handle_httr)$data
176+
d_meta <- REDCapR::redcap_metadata_read( redcap_uri, token, verbose = verbose, handle_httr = handle_httr)$data
177+
d_inst <- REDCapR::redcap_instruments( redcap_uri, token, verbose = verbose, handle_httr = handle_httr)$data
178+
d_proj <- REDCapR::redcap_project_info_read(redcap_uri, token, verbose = verbose, handle_httr = handle_httr)$data
174179

175180
# Determine status of autonumbering, instrument complete status, and decimal mark
176181
.record_field <- d_var$original_field_name[1]

R/redcap-metadata-read.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ redcap_metadata_read <- function(
103103
fields = fields_collapsed
104104
)
105105

106-
# This is the important line that communicates with the REDCap server.
106+
# This is the important call that communicates with the REDCap server.
107107
kernel <-
108108
kernel_api(
109109
redcap_uri = redcap_uri,

R/redcap-metadata-write.R

+15-3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
#' be visible somewhere public. Optional.
2323
#' @param config_options A list of options passed to [httr::POST()].
2424
#' See details at [httr::httr_options()]. Optional.
25+
#' @param handle_httr The value passed to the `handle` parameter of
26+
#' [httr::POST()].
27+
#' This is useful for only unconventional authentication approaches. It
28+
#' should be `NULL` for most institutions. Optional.
2529
#'
2630
#' @return
2731
#' Currently, a list is returned with the following elements:
@@ -79,8 +83,10 @@ redcap_metadata_write <- function(
7983
redcap_uri,
8084
token,
8185
verbose = TRUE,
82-
config_options = NULL
86+
config_options = NULL,
87+
handle_httr = NULL
8388
) {
89+
8490
# This prevents the R CHECK NOTE: 'No visible binding for global variable Note in R CMD check';
8591
# Also see if( getRversion() >= "2.15.1" ) utils::globalVariables(names=c("csv_elements"))
8692
# https://stackoverflow.com/questions/8096313/; https://stackoverflow.com/questions/9439256
@@ -111,8 +117,14 @@ redcap_metadata_write <- function(
111117
returnFormat = "csv"
112118
)
113119

114-
# This is the important line that communicates with the REDCap server.
115-
kernel <- kernel_api(redcap_uri, post_body, config_options)
120+
# This is the important call that communicates with the REDCap server.
121+
kernel <-
122+
kernel_api(
123+
redcap_uri = redcap_uri,
124+
post_body = post_body,
125+
config_options = config_options,
126+
handle_httr = handle_httr
127+
)
116128

117129
if (kernel$success) {
118130
field_count <- as.integer(kernel$raw_text)

R/redcap-next-free-record-name.R

+16-4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
#' be visible somewhere public. Optional.
1818
#' @param config_options A list of options passed to [httr::POST()].
1919
#' See details at [httr::httr_options()]. Optional.
20+
#' @param handle_httr The value passed to the `handle` parameter of
21+
#' [httr::POST()].
22+
#' This is useful for only unconventional authentication approaches. It
23+
#' should be `NULL` for most institutions. Optional.
2024
#'
2125
#' @return
2226
#' a [base::character] vector of either
@@ -68,9 +72,11 @@
6872
redcap_next_free_record_name <- function(
6973
redcap_uri,
7074
token,
71-
verbose = TRUE,
72-
config_options = NULL
75+
verbose = TRUE,
76+
config_options = NULL,
77+
handle_httr = NULL
7378
) {
79+
7480
value_error <- character(0)
7581

7682
checkmate::assert_character(redcap_uri, any.missing=FALSE, len=1, pattern="^.{1,}$")
@@ -86,8 +92,14 @@ redcap_next_free_record_name <- function(
8692
format = "csv"
8793
)
8894

89-
# This is the important line that communicates with the REDCap server.
90-
kernel <- kernel_api(redcap_uri, post_body, config_options)
95+
# This is the important call that communicates with the REDCap server.
96+
kernel <-
97+
kernel_api(
98+
redcap_uri = redcap_uri,
99+
post_body = post_body,
100+
config_options = config_options,
101+
handle_httr = handle_httr
102+
)
91103

92104
if (kernel$success) {
93105
# Don't print the warning in the try block. Print it below,

0 commit comments

Comments
 (0)