Commit 518925c 1 parent df6263f commit 518925c Copy full SHA for 518925c
File tree 2 files changed +18
-7
lines changed
2 files changed +18
-7
lines changed Original file line number Diff line number Diff line change 8
8
# ' project. Required.
9
9
# ' @param token The user-specific string that serves as the password for a
10
10
# ' project. Required.
11
+ # ' @param format Format to download the metadata in. The default is "csv".
11
12
# ' @param forms An array, where each element corresponds to the REDCap form
12
13
# ' of the desired fields. Optional.
13
14
# ' @param forms_collapsed A single string, where the desired forms are
71
72
redcap_metadata_read <- function (
72
73
redcap_uri ,
73
74
token ,
75
+ format = " csv" ,
74
76
forms = NULL ,
75
77
forms_collapsed = " " ,
76
78
fields = NULL ,
@@ -95,7 +97,7 @@ redcap_metadata_read <- function(
95
97
post_body <- list (
96
98
token = token ,
97
99
content = " metadata" ,
98
- format = " csv " ,
100
+ format = format ,
99
101
forms = forms_collapsed ,
100
102
fields = fields_collapsed
101
103
)
@@ -112,11 +114,17 @@ redcap_metadata_read <- function(
112
114
113
115
try(
114
116
# Convert the raw text to a dataset.
115
- ds <-
116
- readr :: read_csv(
117
- kernel $ raw_text ,
118
- col_types = col_types
119
- ),
117
+ if (format == " csv" ) {
118
+ ds <-
119
+ readr :: read_csv(
120
+ kernel $ raw_text ,
121
+ col_types = col_types
122
+ )
123
+ } else if (format == " json" ) {
124
+ json_df <- jsonlite :: fromJSON(kernel $ raw_text )
125
+ json_tibble <- tibble :: as_tibble(json_df )
126
+ ds <- dplyr :: mutate_all(json_tibble , ~ dplyr :: na_if(.x , " " ))
127
+ },
120
128
# Don't print the warning in the try block. Print it below,
121
129
# where it's under the control of the caller.
122
130
silent = TRUE
Original file line number Diff line number Diff line change 19
19
# ' project. Required.
20
20
# ' @param token The user-specific string that serves as the password for a
21
21
# ' project. Required.
22
+ # ' @param format Format to download the metadata in. The default is "csv".
22
23
# ' @param records An array, where each element corresponds to the ID of a
23
24
# ' desired record. Optional.
24
25
# ' @param records_collapsed A single string, where the desired ID values are
@@ -173,6 +174,7 @@ redcap_read <- function(
173
174
continue_on_error = FALSE ,
174
175
redcap_uri ,
175
176
token ,
177
+ format = " csv" ,
176
178
records = NULL , records_collapsed = " " ,
177
179
fields = NULL , fields_collapsed = " " ,
178
180
forms = NULL , forms_collapsed = " " ,
@@ -242,7 +244,8 @@ redcap_read <- function(
242
244
redcap_uri = redcap_uri ,
243
245
token = token ,
244
246
verbose = verbose ,
245
- config_options = config_options
247
+ config_options = config_options ,
248
+ format = format
246
249
)
247
250
248
251
# if (!metadata$success) {
You can’t perform that action at this time.
0 commit comments