mirror of
https://github.com/agdamsbo/REDCapCAST.git
synced 2024-11-22 05:20:23 +01:00
Compare commits
3 Commits
c47f5a9d07
...
5979b972e1
Author | SHA1 | Date | |
---|---|---|---|
5979b972e1 | |||
6c18ed5a01 | |||
82400b2ab9 |
4
NEWS.md
4
NEWS.md
@ -6,11 +6,13 @@
|
|||||||
|
|
||||||
* Fix: `easy_redcap()`: fixed to actually allow project naming. also specifically asks for uri.
|
* Fix: `easy_redcap()`: fixed to actually allow project naming. also specifically asks for uri.
|
||||||
|
|
||||||
|
* Fix: `read_redcap_tables()`: now handles non-longitudinal project without repeatable instruments.
|
||||||
|
|
||||||
* 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: `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: `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()`.
|
* NEW: `ds2ical()` converts data set to ical format with easy glue string for summary and description. Export .ics file with `calendar::ic_write()`.
|
||||||
|
|
||||||
### Other
|
### Other
|
||||||
|
|
||||||
|
29
R/ds2ical.R
29
R/ds2ical.R
@ -3,10 +3,9 @@ utils::globalVariables(c("DTSTART"))
|
|||||||
#' Convert data set to ical file
|
#' Convert data set to ical file
|
||||||
#'
|
#'
|
||||||
#' @param data data set
|
#' @param data data set
|
||||||
#' @param start event start column
|
#' @param start dplyr style event start datetime column name
|
||||||
#' @param location event location column
|
#' @param end dplyr style event end datetime column name
|
||||||
#' @param event.length use lubridate functions to generate "Period" class
|
#' @param location dplyr style event location column name
|
||||||
#' element (default is lubridate::hours(2))
|
|
||||||
#' @param summary.glue.string character string to pass to glue::glue() for event
|
#' @param summary.glue.string character string to pass to glue::glue() for event
|
||||||
#' name (summary). Can take any column from data set.
|
#' name (summary). Can take any column from data set.
|
||||||
#' @param description.glue.string character string to pass to glue::glue() for
|
#' @param description.glue.string character string to pass to glue::glue() for
|
||||||
@ -17,24 +16,24 @@ utils::globalVariables(c("DTSTART"))
|
|||||||
#'
|
#'
|
||||||
#' @examples
|
#' @examples
|
||||||
#' df <- dplyr::tibble(start = c(Sys.time(), Sys.time() + lubridate::days(2)),
|
#' df <- dplyr::tibble(start = c(Sys.time(), Sys.time() + lubridate::days(2)),
|
||||||
#' id = c("1", 3), assessor = "A", location = "111", note = c(NA, "OBS"))
|
#' id = c("1", 3), assessor = "A", location = "111", note = c(NA, "OBS")) |>
|
||||||
#' df |> ds2ical(start, location)
|
#' dplyr::mutate(end= start+lubridate::hours(2))
|
||||||
#' df |> ds2ical(start, location,
|
#' df |> ds2ical()
|
||||||
#' summary.glue.string = "ID {id} [{assessor}] {note}")
|
#' df |> ds2ical(summary.glue.string = "ID {id} [{assessor}] {note}")
|
||||||
#' # Export .ics file: (not run)
|
#' # Export .ics file: (not run)
|
||||||
#' ical <- df |> ds2ical(start, location, description.glue.string = "{note}")
|
#' ical <- df |> ds2ical(start, end, location, description.glue.string = "{note}")
|
||||||
#' # ical |> calendar::ic_write(file=here::here("calendar.ics"))
|
#' # ical |> calendar::ic_write(file=here::here("calendar.ics"))
|
||||||
ds2ical <- function(data,
|
ds2ical <- function(data,
|
||||||
start,
|
start=start,
|
||||||
location,
|
end=end,
|
||||||
|
location=location,
|
||||||
summary.glue.string = "ID {id} [{assessor}]",
|
summary.glue.string = "ID {id} [{assessor}]",
|
||||||
description.glue.string = NULL,
|
description.glue.string = NULL) {
|
||||||
event.length = lubridate::hours(2)) {
|
|
||||||
ds <- data |>
|
ds <- data |>
|
||||||
dplyr::transmute(
|
dplyr::transmute(
|
||||||
SUMMARY = glue::glue(summary.glue.string, .na = ""),
|
SUMMARY = glue::glue(summary.glue.string, .na = ""),
|
||||||
DTSTART = lubridate::ymd_hms({{ start }}, tz = "CET"),
|
DTSTART = lubridate::ymd_hms({{ start }}),
|
||||||
DTEND = DTSTART + event.length,
|
DTEND = lubridate::ymd_hms({{ end }}),
|
||||||
LOCATION = {{ location }}
|
LOCATION = {{ location }}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -33,7 +33,6 @@ read_redcap_tables <- function(uri,
|
|||||||
raw_or_label = "label",
|
raw_or_label = "label",
|
||||||
split_forms = "all",
|
split_forms = "all",
|
||||||
generics = c(
|
generics = c(
|
||||||
"record_id",
|
|
||||||
"redcap_event_name",
|
"redcap_event_name",
|
||||||
"redcap_repeat_instrument",
|
"redcap_repeat_instrument",
|
||||||
"redcap_repeat_instance"
|
"redcap_repeat_instance"
|
||||||
@ -100,6 +99,9 @@ read_redcap_tables <- function(uri,
|
|||||||
m <- focused_metadata(m,names(d))
|
m <- focused_metadata(m,names(d))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (any(generics %in% names(d))){
|
||||||
# Splitting
|
# Splitting
|
||||||
l <- REDCap_split(d,
|
l <- REDCap_split(d,
|
||||||
m,
|
m,
|
||||||
@ -108,7 +110,13 @@ read_redcap_tables <- function(uri,
|
|||||||
|
|
||||||
# Sanitizing split list by removing completely empty rows apart from colnames
|
# Sanitizing split list by removing completely empty rows apart from colnames
|
||||||
# in "generics"
|
# in "generics"
|
||||||
sanitize_split(l,generics)
|
sanitize_split(l,c(names(d)[1],generics))
|
||||||
|
} else {
|
||||||
|
# If none of generics are present, the data base is not longitudinal,
|
||||||
|
# and does not have repeatable events, and therefore splitting does not
|
||||||
|
# make sense. But now we handle that as well.
|
||||||
|
d
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,6 +33,8 @@ dta
|
|||||||
et
|
et
|
||||||
gues
|
gues
|
||||||
hms
|
hms
|
||||||
|
ical
|
||||||
|
ics
|
||||||
immprovements
|
immprovements
|
||||||
jbi
|
jbi
|
||||||
keyring
|
keyring
|
||||||
|
@ -6,28 +6,27 @@
|
|||||||
\usage{
|
\usage{
|
||||||
ds2ical(
|
ds2ical(
|
||||||
data,
|
data,
|
||||||
start,
|
start = start,
|
||||||
location,
|
end = end,
|
||||||
|
location = location,
|
||||||
summary.glue.string = "ID {id} [{assessor}]",
|
summary.glue.string = "ID {id} [{assessor}]",
|
||||||
description.glue.string = NULL,
|
description.glue.string = NULL
|
||||||
event.length = lubridate::hours(2)
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
\arguments{
|
\arguments{
|
||||||
\item{data}{data set}
|
\item{data}{data set}
|
||||||
|
|
||||||
\item{start}{event start column}
|
\item{start}{dplyr style event start datetime column name}
|
||||||
|
|
||||||
\item{location}{event location column}
|
\item{end}{dplyr style event end datetime column name}
|
||||||
|
|
||||||
|
\item{location}{dplyr style event location column name}
|
||||||
|
|
||||||
\item{summary.glue.string}{character string to pass to glue::glue() for event
|
\item{summary.glue.string}{character string to pass to glue::glue() for event
|
||||||
name (summary). Can take any column from data set.}
|
name (summary). Can take any column from data set.}
|
||||||
|
|
||||||
\item{description.glue.string}{character string to pass to glue::glue() for
|
\item{description.glue.string}{character string to pass to glue::glue() for
|
||||||
event description. Can take any column from data set.}
|
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{
|
\value{
|
||||||
tibble of class "ical"
|
tibble of class "ical"
|
||||||
@ -37,11 +36,11 @@ Convert data set to ical file
|
|||||||
}
|
}
|
||||||
\examples{
|
\examples{
|
||||||
df <- dplyr::tibble(start = c(Sys.time(), Sys.time() + lubridate::days(2)),
|
df <- dplyr::tibble(start = c(Sys.time(), Sys.time() + lubridate::days(2)),
|
||||||
id = c("1", 3), assessor = "A", location = "111", note = c(NA, "OBS"))
|
id = c("1", 3), assessor = "A", location = "111", note = c(NA, "OBS")) |>
|
||||||
df |> ds2ical(start, location)
|
dplyr::mutate(end= start+lubridate::hours(2))
|
||||||
df |> ds2ical(start, location,
|
df |> ds2ical()
|
||||||
summary.glue.string = "ID {id} [{assessor}] {note}")
|
df |> ds2ical(summary.glue.string = "ID {id} [{assessor}] {note}")
|
||||||
# Export .ics file: (not run)
|
# Export .ics file: (not run)
|
||||||
ical <- df |> ds2ical(start, location, description.glue.string = "{note}")
|
ical <- df |> ds2ical(start, end, location, description.glue.string = "{note}")
|
||||||
# ical |> calendar::ic_write(file=here::here("calendar.ics"))
|
# ical |> calendar::ic_write(file=here::here("calendar.ics"))
|
||||||
}
|
}
|
||||||
|
@ -13,8 +13,7 @@ read_redcap_tables(
|
|||||||
forms = NULL,
|
forms = NULL,
|
||||||
raw_or_label = "label",
|
raw_or_label = "label",
|
||||||
split_forms = "all",
|
split_forms = "all",
|
||||||
generics = c("record_id", "redcap_event_name", "redcap_repeat_instrument",
|
generics = c("redcap_event_name", "redcap_repeat_instrument", "redcap_repeat_instance")
|
||||||
"redcap_repeat_instance")
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
\arguments{
|
\arguments{
|
||||||
|
Loading…
Reference in New Issue
Block a user