2024-02-27 13:20:21 +01:00
|
|
|
#' Convenience function to download complete instrument, using token storage
|
|
|
|
#' in keyring.
|
2024-01-29 12:43:37 +01:00
|
|
|
#'
|
|
|
|
#' @param key key name in standard keyring for token retrieval.
|
2024-02-05 14:46:37 +01:00
|
|
|
#' @param uri REDCap database API uri
|
2024-01-29 12:43:37 +01:00
|
|
|
#' @param instrument instrument name
|
|
|
|
#' @param raw_or_label raw or label passed to `REDCapR::redcap_read()`
|
|
|
|
#' @param id_name id variable name. Default is "record_id".
|
2024-02-27 13:20:21 +01:00
|
|
|
#' @param records specify the records to download. Index numbers.
|
|
|
|
#' Numeric vector.
|
2024-01-29 12:43:37 +01:00
|
|
|
#'
|
|
|
|
#' @return data.frame
|
|
|
|
#' @export
|
|
|
|
read_redcap_instrument <- function(key,
|
2024-02-27 13:20:21 +01:00
|
|
|
uri,
|
|
|
|
instrument,
|
|
|
|
raw_or_label = "raw",
|
|
|
|
id_name = "record_id",
|
|
|
|
records = NULL) {
|
2024-01-29 12:43:37 +01:00
|
|
|
REDCapCAST::read_redcap_tables(
|
|
|
|
records = records,
|
|
|
|
uri = uri, token = keyring::key_get(key),
|
|
|
|
fields = id_name,
|
|
|
|
forms = instrument,
|
|
|
|
raw_or_label = raw_or_label
|
|
|
|
)[[{{ instrument }}]]
|
|
|
|
}
|