diff --git a/R/easy_redcap.R b/R/easy_redcap.R index 5899fd4..6ad8548 100644 --- a/R/easy_redcap.R +++ b/R/easy_redcap.R @@ -10,7 +10,7 @@ get_api_key <- function(key.name) { if (key.name %in% keyring::key_list()$service) { keyring::key_get(service = key.name) } else { - keyring::key_set(service = key.name, prompt = "Write REDCap API key:") + keyring::key_set(service = key.name, prompt = "Provide REDCap API key:") keyring::key_get(service = key.name) } } @@ -19,40 +19,24 @@ get_api_key <- function(key.name) { #' Secure API key storage and data acquisition in one #' #' @param project.name The name of the current project (for key storage with -#' `keyring::key_set()`) +#' `keyring::key_set()`, using the default keyring) #' @param widen.data argument to widen the exported data #' @param uri REDCap database API uri #' @param ... arguments passed on to `REDCapCAST::read_redcap_tables()` #' #' @return data.frame or list depending on widen.data -#' @importFrom purrr reduce -#' @importFrom dplyr left_join #' @export -easy_redcap <- function(project.name, widen.data = TRUE, uri, ...) { +easy_redcap <- function(project.name, widen.data=TRUE, uri, ...) { key <- get_api_key(key.name = paste0(project.name, "_REDCAP_API")) out <- read_redcap_tables( - token = key, uri = uri, + token = key, ... ) - all_names <- out |> - lapply(names) |> - Reduce(c, x = _) |> - unique() - - if (widen.data) { - if (!any(c("redcap_event_name", "redcap_repeat_instrument") %in% - all_names)) { - if (length(out) == 1) { - out <- out[[1]] - } else { - out <- out |> purrr::reduce(dplyr::left_join) - } - } else { - out <- out |> redcap_wider() - } + if (widen.data){ + out <- out |> redcap_wider() } out diff --git a/man/easy_redcap.Rd b/man/easy_redcap.Rd index 6002b1a..5683456 100644 --- a/man/easy_redcap.Rd +++ b/man/easy_redcap.Rd @@ -8,7 +8,7 @@ easy_redcap(project.name, widen.data = TRUE, uri, ...) } \arguments{ \item{project.name}{The name of the current project (for key storage with -`keyring::key_set()`)} +`keyring::key_set()`, using the default keyring)} \item{widen.data}{argument to widen the exported data}