Skip to content

Commit 4bd5bd8

Browse files
committed
handle for all the record-related calls
and some other functions that they call ref #429
1 parent 84d28d0 commit 4bd5bd8

15 files changed

+186
-32
lines changed

R/redcap-arm-export.R

+14-3
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
#' Currently, a list is returned with the following elements:
@@ -71,7 +75,8 @@ redcap_arm_export <- function(
7175
redcap_uri,
7276
token,
7377
verbose = TRUE,
74-
config_options = NULL
78+
config_options = NULL,
79+
handle_httr = NULL
7580
) {
7681

7782
checkmate::assert_character(redcap_uri, any.missing=FALSE, len=1, pattern="^.{1,}$")
@@ -89,8 +94,14 @@ redcap_arm_export <- function(
8994

9095
try(
9196
{
92-
# This is the important line that communicates with the REDCap server.
93-
kernel <- kernel_api(redcap_uri, post_body, config_options)
97+
# This is the important call that communicates with the REDCap server.
98+
kernel <-
99+
kernel_api(
100+
redcap_uri = redcap_uri,
101+
post_body = post_body,
102+
config_options = config_options,
103+
handle_httr = handle_httr
104+
)
94105
},
95106
# Don't print the warning in the try block. Print it below,
96107
# where it's under the control of the caller.

R/redcap-delete.R

+18-4
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ redcap_delete <- function(
8888
records_to_delete,
8989
arm_of_records_to_delete = NULL,
9090
verbose = TRUE,
91-
config_options = NULL
91+
config_options = NULL,
92+
handle_httr = NULL
9293
) {
9394

9495
checkmate::assert_character(redcap_uri, any.missing=FALSE, len=1, pattern="^.{1,}$")
@@ -107,7 +108,14 @@ redcap_delete <- function(
107108
sprintf("records[%i]", seq_along(records_to_delete) - 1)
108109
)
109110

110-
arms_call <- redcap_arm_export(redcap_uri, token, verbose = FALSE, config_options)
111+
arms_call <-
112+
redcap_arm_export(
113+
redcap_uri = redcap_uri,
114+
token = token,
115+
verbose = FALSE,
116+
config_options = config_options,
117+
handle_httr = handle_httr
118+
)
111119

112120
if (arms_call$has_arms && is.null(arm_of_records_to_delete)) {
113121
stop("This REDCap project has arms. Please specify which arm contains the records to be deleted.")
@@ -134,8 +142,14 @@ redcap_delete <- function(
134142

135143
try(
136144
{
137-
# This is the important line that communicates with the REDCap server.
138-
kernel <- kernel_api(redcap_uri, post_body, config_options)
145+
# This is the important call that communicates with the REDCap server.
146+
kernel <-
147+
kernel_api(
148+
redcap_uri = redcap_uri,
149+
post_body = post_body,
150+
config_options = config_options,
151+
handle_httr = handle_httr
152+
)
139153
},
140154
# Don't print the warning in the try block. Print it below,
141155
# where it's under the control of the caller.

R/redcap-read-oneshot-eav.R

+33-5
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,21 @@
6464
#' are recommended in a data export if the data will be re-imported into a
6565
#' REDCap project. Default is `FALSE`.
6666
#'
67+
#' @param http_response_encoding The encoding value passed to
68+
#' [httr::content()]. Defaults to 'UTF-8'.
69+
#' @param locale a [readr::locale()] object to specify preferences like
70+
#' number, date, and time formats. This object is passed to
71+
#' [readr::read_csv()]. Defaults to [readr::default_locale()].
6772
#' @param verbose A boolean value indicating if `message`s should be printed
6873
#' to the R console during the operation. The verbose output might contain
6974
#' sensitive information (*e.g.* PHI), so turn this off if the output might
7075
#' be visible somewhere public. Optional.
7176
#' @param config_options A list of options passed to [httr::POST()].
7277
#' See details at [httr::httr_options()]. Optional.
78+
#' @param handle_httr The value passed to the `handle` parameter of
79+
#' [httr::POST()].
80+
#' This is useful for only unconventional authentication approaches. It
81+
#' should be `NULL` for most institutions. Optional.
7382
#'
7483
#' @return
7584
#' Currently, a list is returned with the following elements:
@@ -165,8 +174,11 @@ redcap_read_oneshot_eav <- function(
165174

166175
# placeholder: guess_type
167176
# placeholder: guess_max
177+
http_response_encoding = "UTF-8",
178+
locale = readr::default_locale(),
168179
verbose = TRUE,
169-
config_options = NULL
180+
config_options = NULL,
181+
handle_httr = NULL
170182
) {
171183

172184
checkmate::assert_character(redcap_uri , any.missing=FALSE, len=1, pattern="^.{1,}$")
@@ -194,6 +206,8 @@ redcap_read_oneshot_eav <- function(
194206

195207
# placeholder: checkmate::assert_logical( guess_type , any.missing=FALSE, len=1)
196208
# placeholder: checkmate::assert_numeric( guess_max , any.missing=FALSE, len=1, lower=1)
209+
checkmate::assert_character(http_response_encoding , any.missing=FALSE, len=1)
210+
checkmate::assert_class( locale, "locale" , null.ok = FALSE)
197211
checkmate::assert_logical( verbose , any.missing=FALSE, len=1, null.ok=TRUE)
198212
checkmate::assert_list( config_options , any.missing=TRUE , null.ok=TRUE)
199213

@@ -233,8 +247,14 @@ redcap_read_oneshot_eav <- function(
233247
if (0L < nchar(forms_collapsed )) post_body$forms <- forms_collapsed
234248
if (0L < nchar(events_collapsed )) post_body$events <- events_collapsed
235249

236-
# This is the important line that communicates with the REDCap server.
237-
kernel <- kernel_api(redcap_uri, post_body, config_options)
250+
# This is the important call that communicates with the REDCap server.
251+
kernel <- kernel_api(
252+
redcap_uri = redcap_uri,
253+
post_body = post_body,
254+
config_options = config_options,
255+
encoding = http_response_encoding,
256+
handle_httr = handle_httr
257+
)
238258

239259
if (!kernel$success) {
240260
error_message <- sprintf(
@@ -248,16 +268,24 @@ redcap_read_oneshot_eav <- function(
248268
REDCapR::redcap_metadata_read(
249269
redcap_uri,
250270
token,
251-
forms_collapsed = forms_collapsed
271+
forms_collapsed = forms_collapsed,
272+
handle_httr = handle_httr
273+
)$data
274+
275+
ds_variable <-
276+
REDCapR::redcap_variables(
277+
redcap_uri = redcap_uri,
278+
token = token,
279+
handle_httr = handle_httr
252280
)$data
253-
ds_variable <- REDCapR::redcap_variables(redcap_uri, token)$data
254281

255282
if (kernel$success) {
256283
try(
257284
{
258285
ds_eav <-
259286
readr::read_csv(
260287
file = I(kernel$raw_text),
288+
locale = locale,
261289
show_col_types = FALSE
262290
)
263291

R/redcap-read-oneshot.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,8 @@ redcap_read_oneshot <- function(
232232

233233
checkmate::assert_logical( guess_type , any.missing=FALSE, len=1)
234234
checkmate::assert_numeric( guess_max , any.missing=FALSE, len=1, lower=1)
235-
checkmate::assert_character(http_response_encoding , any.missing=FALSE, len=1)
236235

236+
checkmate::assert_character(http_response_encoding , any.missing=FALSE, len=1)
237237
checkmate::assert_class( locale, "locale" , null.ok = FALSE)
238238
checkmate::assert_logical( verbose , any.missing=FALSE, len=1, null.ok=TRUE)
239239
checkmate::assert_list( config_options , any.missing=TRUE , null.ok=TRUE)
@@ -277,7 +277,7 @@ redcap_read_oneshot <- function(
277277
if (0L < nchar(forms_collapsed )) post_body$forms <- forms_collapsed
278278
if (0L < nchar(events_collapsed )) post_body$events <- events_collapsed
279279

280-
# This is the important line that communicates with the REDCap server.
280+
# This is the important call that communicates with the REDCap server.
281281
kernel <- kernel_api(
282282
redcap_uri = redcap_uri,
283283
post_body = post_body,

R/redcap-report.R

+14-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:
@@ -130,7 +134,8 @@ redcap_report <- function(
130134
guess_type = TRUE,
131135
guess_max = 1000,
132136
verbose = TRUE,
133-
config_options = NULL
137+
config_options = NULL,
138+
handle_httr = NULL
134139
) {
135140

136141
checkmate::assert_character(redcap_uri , any.missing=FALSE, len=1, pattern="^.{1,}$")
@@ -160,8 +165,14 @@ redcap_report <- function(
160165
exportCheckboxLabel = tolower(as.character(export_checkbox_label))
161166
)
162167

163-
# This is the important line that communicates with the REDCap server.
164-
kernel <- kernel_api(redcap_uri, post_body, config_options)
168+
# This is the important call that communicates with the REDCap server.
169+
kernel <-
170+
kernel_api(
171+
redcap_uri = redcap_uri,
172+
post_body = post_body,
173+
config_options = config_options,
174+
handle_httr = handle_httr
175+
)
165176

166177
if (kernel$success) {
167178
col_types <-

R/redcap-variables.R

+14-3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
#' be visible somewhere public. Optional.
1919
#' @param config_options A list of options passed to [httr::POST()].
2020
#' See details at [httr::httr_options()]. Optional.
21+
#' @param handle_httr The value passed to the `handle` parameter of
22+
#' [httr::POST()].
23+
#' This is useful for only unconventional authentication approaches. It
24+
#' should be `NULL` for most institutions. Optional.
2125
#'
2226
#' @return
2327
#' Currently, a list is returned with the following elements,
@@ -63,7 +67,8 @@ redcap_variables <- function(
6367
redcap_uri,
6468
token,
6569
verbose = TRUE,
66-
config_options = NULL
70+
config_options = NULL,
71+
handle_httr = NULL
6772
) {
6873

6974
checkmate::assert_character(redcap_uri, any.missing=FALSE, len=1, pattern="^.{1,}$")
@@ -78,8 +83,14 @@ redcap_variables <- function(
7883
format = "csv"
7984
)
8085

81-
# This is the important line that communicates with the REDCap server.
82-
kernel <- kernel_api(redcap_uri, post_body, config_options)
86+
# This is the important call that communicates with the REDCap server.
87+
kernel <-
88+
kernel_api(
89+
redcap_uri = redcap_uri,
90+
post_body = post_body,
91+
config_options = config_options,
92+
handle_httr = handle_httr
93+
)
8394

8495
if (kernel$success) {
8596
try(

R/redcap-write-oneshot.R

+14-3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
#' be visible somewhere public. Optional.
3232
#' @param config_options A list of options passed to [httr::POST()].
3333
#' See details at [httr::httr_options()]. Optional.
34+
#' @param handle_httr The value passed to the `handle` parameter of
35+
#' [httr::POST()].
36+
#' This is useful for only unconventional authentication approaches. It
37+
#' should be `NULL` for most institutions. Optional.
3438
#'
3539
#' @return
3640
#' Currently, a list is returned with the following elements:
@@ -103,7 +107,8 @@ redcap_write_oneshot <- function(
103107
overwrite_with_blanks = TRUE,
104108
convert_logical_to_integer = FALSE,
105109
verbose = TRUE,
106-
config_options = NULL
110+
config_options = NULL,
111+
handle_httr = NULL
107112
) {
108113

109114
# This prevents the R CHECK NOTE: 'No visible binding for global variable Note in R CMD check';
@@ -152,8 +157,14 @@ redcap_write_oneshot <- function(
152157
returnFormat = "csv"
153158
)
154159

155-
# This is the important line that communicates with the REDCap server.
156-
kernel <- kernel_api(redcap_uri, post_body, config_options)
160+
# This is the important call that communicates with the REDCap server.
161+
kernel <-
162+
kernel_api(
163+
redcap_uri = redcap_uri,
164+
post_body = post_body,
165+
config_options = config_options,
166+
handle_httr = handle_httr
167+
)
157168

158169
if (kernel$success) {
159170
elements <- unlist(strsplit(kernel$raw_text, split="\\n"))

R/redcap-write.R

+9-2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@
3737
#' be visible somewhere public. Optional.
3838
#' @param config_options A list of options passed to [httr::POST()].
3939
#' See details at [httr::httr_options()]. Optional.
40+
#' @param handle_httr The value passed to the `handle` parameter of
41+
#' [httr::POST()].
42+
#' This is useful for only unconventional authentication approaches. It
43+
#' should be `NULL` for most institutions. Optional.
4044
#'
4145
#' @return
4246
#' Currently, a list is returned with the following elements:
@@ -118,7 +122,8 @@ redcap_write <- function(
118122
overwrite_with_blanks = TRUE,
119123
convert_logical_to_integer = FALSE,
120124
verbose = TRUE,
121-
config_options = NULL
125+
config_options = NULL,
126+
handle_httr = NULL
122127
) {
123128

124129
start_time <- base::Sys.time()
@@ -143,6 +148,7 @@ redcap_write <- function(
143148
format(nrow(ds_to_write), big.mark = ",", scientific = FALSE, trim = TRUE),
144149
Sys.time()
145150
))
151+
146152
for (i in seq_along(ds_glossary$id)) {
147153
selected_indices <- seq(
148154
from = ds_glossary$start_index[i],
@@ -165,7 +171,8 @@ redcap_write <- function(
165171
overwrite_with_blanks = overwrite_with_blanks,
166172
convert_logical_to_integer = convert_logical_to_integer,
167173
verbose = verbose,
168-
config_options = config_options
174+
config_options = config_options,
175+
handle_httr = handle_httr
169176
)
170177

171178
lst_status_code[[i]] <- write_result$status_code

man/redcap_arm_export.Rd

+12-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/redcap_delete.Rd

+7-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)