drops specified record name and takes name of first field for sanitizing

This commit is contained in:
Andreas Gammelgaard Damsbo 2024-02-05 21:34:16 +01:00
parent c47f5a9d07
commit 82400b2ab9
4 changed files with 38 additions and 33 deletions

View File

@ -3,10 +3,9 @@ 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 start dplyr style event start datetime column name
#' @param end dplyr style event end datetime column name
#' @param location dplyr style event location column name
#' @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
@ -17,24 +16,24 @@ utils::globalVariables(c("DTSTART"))
#'
#' @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}")
#' id = c("1", 3), assessor = "A", location = "111", note = c(NA, "OBS")) |>
#' dplyr::mutate(end= start+lubridate::hours(2))
#' df |> ds2ical()
#' df |> ds2ical(summary.glue.string = "ID {id} [{assessor}] {note}")
#' # 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"))
ds2ical <- function(data,
start,
location,
start=start,
end=end,
location=location,
summary.glue.string = "ID {id} [{assessor}]",
description.glue.string = NULL,
event.length = lubridate::hours(2)) {
description.glue.string = NULL) {
ds <- data |>
dplyr::transmute(
SUMMARY = glue::glue(summary.glue.string, .na = ""),
DTSTART = lubridate::ymd_hms({{ start }}, tz = "CET"),
DTEND = DTSTART + event.length,
DTSTART = lubridate::ymd_hms({{ start }}),
DTEND = lubridate::ymd_hms({{ end }}),
LOCATION = {{ location }}
)

View File

@ -33,7 +33,6 @@ read_redcap_tables <- function(uri,
raw_or_label = "label",
split_forms = "all",
generics = c(
"record_id",
"redcap_event_name",
"redcap_repeat_instrument",
"redcap_repeat_instance"
@ -100,6 +99,9 @@ read_redcap_tables <- function(uri,
m <- focused_metadata(m,names(d))
}
if (any(generics %in% names(d))){
# Splitting
l <- REDCap_split(d,
m,
@ -108,7 +110,13 @@ read_redcap_tables <- function(uri,
# Sanitizing split list by removing completely empty rows apart from colnames
# 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
}
}

View File

@ -6,28 +6,27 @@
\usage{
ds2ical(
data,
start,
location,
start = start,
end = end,
location = location,
summary.glue.string = "ID {id} [{assessor}]",
description.glue.string = NULL,
event.length = lubridate::hours(2)
description.glue.string = NULL
)
}
\arguments{
\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
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"
@ -37,11 +36,11 @@ 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}")
id = c("1", 3), assessor = "A", location = "111", note = c(NA, "OBS")) |>
dplyr::mutate(end= start+lubridate::hours(2))
df |> ds2ical()
df |> ds2ical(summary.glue.string = "ID {id} [{assessor}] {note}")
# 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"))
}

View File

@ -13,8 +13,7 @@ read_redcap_tables(
forms = NULL,
raw_or_label = "label",
split_forms = "all",
generics = c("record_id", "redcap_event_name", "redcap_repeat_instrument",
"redcap_repeat_instance")
generics = c("redcap_event_name", "redcap_repeat_instrument", "redcap_repeat_instance")
)
}
\arguments{