mirror of
https://github.com/agdamsbo/REDCapCAST.git
synced 2024-11-22 05:20:23 +01:00
Compare commits
6 Commits
bd29de23c9
...
c47f5a9d07
Author | SHA1 | Date | |
---|---|---|---|
c47f5a9d07 | |||
bcc57ce924 | |||
7c1965cb7c | |||
904b76eb96 | |||
385973e8da | |||
28dc2ba09e |
12
DESCRIPTION
12
DESCRIPTION
@ -1,6 +1,6 @@
|
||||
Package: REDCapCAST
|
||||
Title: REDCap Castellated Data Handling
|
||||
Version: 24.1.2
|
||||
Version: 24.2.1
|
||||
Authors@R: c(
|
||||
person("Andreas Gammelgaard", "Damsbo", email = "agdamsbo@clin.au.dk",
|
||||
role = c("aut", "cre"),comment = c(ORCID = "0000-0002-7559-1154")),
|
||||
@ -34,7 +34,9 @@ Suggests:
|
||||
ggplot2,
|
||||
haven,
|
||||
here,
|
||||
styler
|
||||
styler,
|
||||
devtools,
|
||||
roxygen2
|
||||
License: GPL (>= 3)
|
||||
Encoding: UTF-8
|
||||
LazyData: true
|
||||
@ -49,13 +51,17 @@ Imports:
|
||||
keyring,
|
||||
purrr,
|
||||
readr,
|
||||
stats
|
||||
stats,
|
||||
calendar,
|
||||
lubridate,
|
||||
glue
|
||||
Collate:
|
||||
'utils.r'
|
||||
'process_user_input.r'
|
||||
'REDCap_split.r'
|
||||
'ds2dd.R'
|
||||
'ds2dd_detailed.R'
|
||||
'ds2ical.R'
|
||||
'easy_redcap.R'
|
||||
'read_redcap_instrument.R'
|
||||
'read_redcap_tables.R'
|
||||
|
@ -5,6 +5,7 @@ export(clean_redcap_name)
|
||||
export(d2w)
|
||||
export(ds2dd)
|
||||
export(ds2dd_detailed)
|
||||
export(ds2ical)
|
||||
export(easy_redcap)
|
||||
export(focused_metadata)
|
||||
export(get_api_key)
|
||||
|
6
NEWS.md
6
NEWS.md
@ -1,13 +1,17 @@
|
||||
# REDCapCAST 24.1.2
|
||||
# REDCapCAST 24.2.1
|
||||
|
||||
### Functions
|
||||
|
||||
* Fix: `ds2dd()`: uses correct default dd column names. Will be deprecated.
|
||||
|
||||
* Fix: `easy_redcap()`: fixed to actually allow project naming. also specifically asks for uri.
|
||||
|
||||
* NEW: `ds2dd_detailed()`: extension of the `ds2dd()`, which serves to preserve as much metadata as possible automatically. Depends on a group of helper functions also introduced. Of special note is the `guess_time_only_filter()`, which will try to guess which columns/variables should be formatted as time only formats. Supports hms time format. DETAILED INSTRUCTION AND VIGNETTE IS PENDING.
|
||||
|
||||
* NEW: `read_redcap_instrument()` convenience function to retrieve complete instrument. Goes a little against the focused approach. DETAILED INSTRUCTION IS PENDING.
|
||||
|
||||
* NEW: `ds2ical()` converts data set to ical format with easy glue string for summary and description. Export ics file with `calendar::ic_write()`.
|
||||
|
||||
### Other
|
||||
|
||||
I believe `renv` has now been added and runs correctly. After clone, do `renv::restore()` to install all necessary package to modify the package.
|
||||
|
59
R/ds2ical.R
Normal file
59
R/ds2ical.R
Normal file
@ -0,0 +1,59 @@
|
||||
utils::globalVariables(c("DTSTART"))
|
||||
|
||||
#' Convert data set to ical file
|
||||
#'
|
||||
#' @param data data set
|
||||
#' @param start event start column
|
||||
#' @param location event location column
|
||||
#' @param event.length use lubridate functions to generate "Period" class
|
||||
#' element (default is lubridate::hours(2))
|
||||
#' @param summary.glue.string character string to pass to glue::glue() for event
|
||||
#' name (summary). Can take any column from data set.
|
||||
#' @param description.glue.string character string to pass to glue::glue() for
|
||||
#' event description. Can take any column from data set.
|
||||
#'
|
||||
#' @return tibble of class "ical"
|
||||
#' @export
|
||||
#'
|
||||
#' @examples
|
||||
#' df <- dplyr::tibble(start = c(Sys.time(), Sys.time() + lubridate::days(2)),
|
||||
#' id = c("1", 3), assessor = "A", location = "111", note = c(NA, "OBS"))
|
||||
#' df |> ds2ical(start, location)
|
||||
#' df |> ds2ical(start, location,
|
||||
#' summary.glue.string = "ID {id} [{assessor}] {note}")
|
||||
#' # Export .ics file: (not run)
|
||||
#' ical <- df |> ds2ical(start, location, description.glue.string = "{note}")
|
||||
#' # ical |> calendar::ic_write(file=here::here("calendar.ics"))
|
||||
ds2ical <- function(data,
|
||||
start,
|
||||
location,
|
||||
summary.glue.string = "ID {id} [{assessor}]",
|
||||
description.glue.string = NULL,
|
||||
event.length = lubridate::hours(2)) {
|
||||
ds <- data |>
|
||||
dplyr::transmute(
|
||||
SUMMARY = glue::glue(summary.glue.string, .na = ""),
|
||||
DTSTART = lubridate::ymd_hms({{ start }}, tz = "CET"),
|
||||
DTEND = DTSTART + event.length,
|
||||
LOCATION = {{ location }}
|
||||
)
|
||||
|
||||
if (!is.null(description.glue.string)){
|
||||
ds <- dplyr::tibble(ds,
|
||||
dplyr::transmute(data,
|
||||
DESCRIPTION = glue::glue(
|
||||
description.glue.string,
|
||||
.na = ""
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
ds |>
|
||||
(\(x){
|
||||
x |>
|
||||
dplyr::mutate(UID = replicate(nrow(x), calendar::ic_guid()))
|
||||
})() |>
|
||||
dplyr::filter(!is.na(DTSTART)) |>
|
||||
calendar::ical()
|
||||
}
|
@ -21,19 +21,19 @@ get_api_key <- function(key.name) {
|
||||
#' @param project.name The name of the current project (for key storage with
|
||||
#' `keyring::key_set()`)
|
||||
#' @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, ...) {
|
||||
project.name <- "ENIGMA"
|
||||
|
||||
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,
|
||||
...
|
||||
)
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
#' Convenience function to download complete instrument, using token storage in keyring.
|
||||
#'
|
||||
#' @param key key name in standard keyring for token retrieval.
|
||||
#' @param uri redcap api url
|
||||
#' @param uri REDCap database API uri
|
||||
#' @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".
|
||||
@ -11,7 +11,7 @@
|
||||
#' @export
|
||||
read_redcap_instrument <- function(key,
|
||||
uri,
|
||||
instrument = "rbans",
|
||||
instrument,
|
||||
raw_or_label = "raw",
|
||||
id_name = "record_id",
|
||||
records = NULL) {
|
||||
|
@ -5,7 +5,7 @@
|
||||
#' events using the built-in focused_metadata including some clean-up.
|
||||
#' Works with classical and longitudinal projects with or without repeating
|
||||
#' instruments.
|
||||
#' @param uri REDCap database uri
|
||||
#' @param uri REDCap database API uri
|
||||
#' @param token API token
|
||||
#' @param records records to download
|
||||
#' @param fields fields to download
|
||||
|
47
man/ds2ical.Rd
Normal file
47
man/ds2ical.Rd
Normal file
@ -0,0 +1,47 @@
|
||||
% Generated by roxygen2: do not edit by hand
|
||||
% Please edit documentation in R/ds2ical.R
|
||||
\name{ds2ical}
|
||||
\alias{ds2ical}
|
||||
\title{Convert data set to ical file}
|
||||
\usage{
|
||||
ds2ical(
|
||||
data,
|
||||
start,
|
||||
location,
|
||||
summary.glue.string = "ID {id} [{assessor}]",
|
||||
description.glue.string = NULL,
|
||||
event.length = lubridate::hours(2)
|
||||
)
|
||||
}
|
||||
\arguments{
|
||||
\item{data}{data set}
|
||||
|
||||
\item{start}{event start column}
|
||||
|
||||
\item{location}{event location column}
|
||||
|
||||
\item{summary.glue.string}{character string to pass to glue::glue() for event
|
||||
name (summary). Can take any column from data set.}
|
||||
|
||||
\item{description.glue.string}{character string to pass to glue::glue() for
|
||||
event description. Can take any column from data set.}
|
||||
|
||||
\item{event.length}{use lubridate functions to generate "Period" class
|
||||
element (default is lubridate::hours(2))}
|
||||
}
|
||||
\value{
|
||||
tibble of class "ical"
|
||||
}
|
||||
\description{
|
||||
Convert data set to ical file
|
||||
}
|
||||
\examples{
|
||||
df <- dplyr::tibble(start = c(Sys.time(), Sys.time() + lubridate::days(2)),
|
||||
id = c("1", 3), assessor = "A", location = "111", note = c(NA, "OBS"))
|
||||
df |> ds2ical(start, location)
|
||||
df |> ds2ical(start, location,
|
||||
summary.glue.string = "ID {id} [{assessor}] {note}")
|
||||
# Export .ics file: (not run)
|
||||
ical <- df |> ds2ical(start, location, description.glue.string = "{note}")
|
||||
# ical |> calendar::ic_write(file=here::here("calendar.ics"))
|
||||
}
|
@ -4,7 +4,7 @@
|
||||
\alias{easy_redcap}
|
||||
\title{Secure API key storage and data acquisition in one}
|
||||
\usage{
|
||||
easy_redcap(project.name, widen.data = TRUE, ...)
|
||||
easy_redcap(project.name, widen.data = TRUE, uri, ...)
|
||||
}
|
||||
\arguments{
|
||||
\item{project.name}{The name of the current project (for key storage with
|
||||
@ -12,6 +12,8 @@ easy_redcap(project.name, widen.data = TRUE, ...)
|
||||
|
||||
\item{widen.data}{argument to widen the exported data}
|
||||
|
||||
\item{uri}{REDCap database API uri}
|
||||
|
||||
\item{...}{arguments passed on to `REDCapCAST::read_redcap_tables()`}
|
||||
}
|
||||
\value{
|
||||
|
@ -7,7 +7,7 @@
|
||||
read_redcap_instrument(
|
||||
key,
|
||||
uri,
|
||||
instrument = "rbans",
|
||||
instrument,
|
||||
raw_or_label = "raw",
|
||||
id_name = "record_id",
|
||||
records = NULL
|
||||
@ -16,7 +16,7 @@ read_redcap_instrument(
|
||||
\arguments{
|
||||
\item{key}{key name in standard keyring for token retrieval.}
|
||||
|
||||
\item{uri}{redcap api url}
|
||||
\item{uri}{REDCap database API uri}
|
||||
|
||||
\item{instrument}{instrument name}
|
||||
|
||||
|
@ -18,7 +18,7 @@ read_redcap_tables(
|
||||
)
|
||||
}
|
||||
\arguments{
|
||||
\item{uri}{REDCap database uri}
|
||||
\item{uri}{REDCap database API uri}
|
||||
|
||||
\item{token}{API token}
|
||||
|
||||
|
37
renv.lock
37
renv.lock
@ -93,6 +93,19 @@
|
||||
],
|
||||
"Hash": "9fe98599ca456d6552421db0d6772d8f"
|
||||
},
|
||||
"calendar": {
|
||||
"Package": "calendar",
|
||||
"Version": "0.0.1",
|
||||
"Source": "Repository",
|
||||
"Repository": "CRAN",
|
||||
"Requirements": [
|
||||
"R",
|
||||
"lubridate",
|
||||
"methods",
|
||||
"tibble"
|
||||
],
|
||||
"Hash": "ab478f470a5203ff9990e42d916005b0"
|
||||
},
|
||||
"checkmate": {
|
||||
"Package": "checkmate",
|
||||
"Version": "2.3.1",
|
||||
@ -297,6 +310,19 @@
|
||||
],
|
||||
"Hash": "b8552d117e1b808b09a832f589b79035"
|
||||
},
|
||||
"lubridate": {
|
||||
"Package": "lubridate",
|
||||
"Version": "1.9.3",
|
||||
"Source": "Repository",
|
||||
"Repository": "CRAN",
|
||||
"Requirements": [
|
||||
"R",
|
||||
"generics",
|
||||
"methods",
|
||||
"timechange"
|
||||
],
|
||||
"Hash": "680ad542fbcf801442c83a6ac5a2126c"
|
||||
},
|
||||
"magrittr": {
|
||||
"Package": "magrittr",
|
||||
"Version": "2.0.3",
|
||||
@ -549,6 +575,17 @@
|
||||
],
|
||||
"Hash": "79540e5fcd9e0435af547d885f184fd5"
|
||||
},
|
||||
"timechange": {
|
||||
"Package": "timechange",
|
||||
"Version": "0.3.0",
|
||||
"Source": "Repository",
|
||||
"Repository": "CRAN",
|
||||
"Requirements": [
|
||||
"R",
|
||||
"cpp11"
|
||||
],
|
||||
"Hash": "c5f3c201b931cd6474d17d8700ccb1c8"
|
||||
},
|
||||
"tzdb": {
|
||||
"Package": "tzdb",
|
||||
"Version": "0.4.0",
|
||||
|
Loading…
Reference in New Issue
Block a user