mirror of
https://github.com/agdamsbo/REDCapCAST.git
synced 2024-11-24 22:11:55 +01:00
reflects changes to redcap_wider()
This commit is contained in:
parent
0ce516c297
commit
edd5334df8
@ -10,7 +10,7 @@ get_api_key <- function(key.name) {
|
|||||||
if (key.name %in% keyring::key_list()$service) {
|
if (key.name %in% keyring::key_list()$service) {
|
||||||
keyring::key_get(service = key.name)
|
keyring::key_get(service = key.name)
|
||||||
} else {
|
} 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)
|
keyring::key_get(service = key.name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -19,41 +19,25 @@ get_api_key <- function(key.name) {
|
|||||||
#' Secure API key storage and data acquisition in one
|
#' Secure API key storage and data acquisition in one
|
||||||
#'
|
#'
|
||||||
#' @param project.name The name of the current project (for key storage with
|
#' @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 widen.data argument to widen the exported data
|
||||||
#' @param uri REDCap database API uri
|
#' @param uri REDCap database API uri
|
||||||
#' @param ... arguments passed on to `REDCapCAST::read_redcap_tables()`
|
#' @param ... arguments passed on to `REDCapCAST::read_redcap_tables()`
|
||||||
#'
|
#'
|
||||||
#' @return data.frame or list depending on widen.data
|
#' @return data.frame or list depending on widen.data
|
||||||
#' @importFrom purrr reduce
|
|
||||||
#' @importFrom dplyr left_join
|
|
||||||
#' @export
|
#' @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"))
|
key <- get_api_key(key.name = paste0(project.name, "_REDCAP_API"))
|
||||||
|
|
||||||
out <- read_redcap_tables(
|
out <- read_redcap_tables(
|
||||||
token = key,
|
|
||||||
uri = uri,
|
uri = uri,
|
||||||
|
token = key,
|
||||||
...
|
...
|
||||||
)
|
)
|
||||||
|
|
||||||
all_names <- out |>
|
|
||||||
lapply(names) |>
|
|
||||||
Reduce(c, x = _) |>
|
|
||||||
unique()
|
|
||||||
|
|
||||||
if (widen.data){
|
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()
|
out <- out |> redcap_wider()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
out
|
out
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ easy_redcap(project.name, widen.data = TRUE, uri, ...)
|
|||||||
}
|
}
|
||||||
\arguments{
|
\arguments{
|
||||||
\item{project.name}{The name of the current project (for key storage with
|
\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}
|
\item{widen.data}{argument to widen the exported data}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user