From c98acb3c547330097f746a089878c6a7e23d6562 Mon Sep 17 00:00:00 2001 From: Adam Forys Date: Tue, 23 Jul 2024 12:01:54 +0200 Subject: [PATCH] Cleanup dependencies and fix documentation --- DESCRIPTION | 21 +++++++------ R/assertions.R | 6 +--- R/ct.R | 9 +++--- R/derive_blfl.R | 2 ++ R/domain_example.R | 7 +++-- man/dtc_timepart.Rd | 72 ++++++++++++++++++--------------------------- 6 files changed, 52 insertions(+), 65 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 7ea9063e..c8e33632 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -36,18 +36,15 @@ Roxygen: list(markdown = TRUE) RoxygenNote: 7.3.2 Depends: R (>= 4.2) Imports: - admiraldev, + admiraldev (>= 1.1.0), dplyr (>= 1.0.0), - memoise, - assertthat, - purrr (>= 0.3.3), - rlang (>= 0.4.4), + purrr (>= 1.0.1), + rlang (>= 1.0.2), + tibble (>= 3.2.0), + vctrs (>= 0.5.0), stringr (>= 1.4.0), - tibble, - vctrs, - readr, - glue, - DT, + memoise (>= 2.0.1), + assertthat, pillar Suggests: knitr, @@ -56,7 +53,9 @@ Suggests: magrittr, rmarkdown, spelling, - testthat (>= 3.1.7) + testthat (>= 3.1.7), + DT, + readr VignetteBuilder: knitr Config/testthat/edition: 3 Config/testthat/parallel: true diff --git a/R/assertions.R b/R/assertions.R index 8228c4ee..7f960b72 100644 --- a/R/assertions.R +++ b/R/assertions.R @@ -5,11 +5,7 @@ assert_logical_vector <- function(arg, optional = FALSE) { } if (!is.logical(arg)) { - err_msg <- sprintf( - "`arg` must be a logical vector but is %s.", - admiraldev::what_is_it(arg) - ) - rlang::abort(err_msg) + cli::cli_abort('`arg` must be a logical vector but is {.obj_type_friendly {arg}}') } invisible(arg) diff --git a/R/ct.R b/R/ct.R index ab5efb00..ccbd904f 100644 --- a/R/ct.R +++ b/R/ct.R @@ -103,11 +103,11 @@ assert_ct_spec <- function(ct_spec, optional = FALSE) { } if (!is.null(ct_spec) && anyNA(ct_spec[[ct_spec_vars("ct_clst")]])) { - rlang::abort(glue::glue("`{ct_spec_vars('ct_clst')}` can't have any NA values.")) + rlang::abort(stringr::str_glue("`{ct_spec_vars('ct_clst')}` can't have any NA values.")) } if (!is.null(ct_spec) && anyNA(ct_spec[[ct_spec_vars("to")]])) { - rlang::abort(glue::glue("`{ct_spec_vars('to')}` can't have any NA values.")) + rlang::abort(stringr::str_glue("`{ct_spec_vars('to')}` can't have any NA values.")) } invisible(ct_spec) @@ -340,7 +340,8 @@ ct_map <- #' #' @export read_ct_spec <- function(file = stop("`file` must be specified")) { - ct_spec <- readr::read_csv(file = file, col_types = "c") + ct_spec <- read.csv(file = file, na.strings = c("NA", ""), colClasses = "character") |> + tibble::as_tibble() assert_ct_spec(ct_spec) ct_spec @@ -388,7 +389,7 @@ ct_spec_example <- function(example) { if (identical(local_path, "")) { stop( - glue::glue( + stringr::str_glue( "'{example}' does not match any ct spec files. Run `ct_spec_example()` for options." ), call. = FALSE diff --git a/R/derive_blfl.R b/R/derive_blfl.R index 0c3e2508..9d38732f 100644 --- a/R/derive_blfl.R +++ b/R/derive_blfl.R @@ -54,6 +54,8 @@ dtc_datepart <- function(dtc, partial_as_na = TRUE) { #' @export #' #' @keywords internal +#' +#' @examples #' ## Partial or missing times set to NA and seconds ignored by default #' sdtm.oak:::dtc_timepart( #' c(NA, "", "2021-12-25", "2021-12-25T12", "2021-12-25T12:30", "2021-12-25T12:30:59") diff --git a/R/domain_example.R b/R/domain_example.R index f63578a6..58aae4e4 100644 --- a/R/domain_example.R +++ b/R/domain_example.R @@ -80,7 +80,7 @@ domain_example <- function(example) { if (identical(local_path, "")) { stop( - glue::glue( + stringr::str_glue( "'{example}' does not match any domain example files. Run `domain_example()` for options." ), call. = FALSE @@ -125,5 +125,8 @@ read_domain_example <- function(example) { } path <- domain_example(example) - readr::read_rds(file = path) + con <- file(path) + on.exit(close(con)) + + readRDS(con) } diff --git a/man/dtc_timepart.Rd b/man/dtc_timepart.Rd index 84d648a7..5ec86651 100644 --- a/man/dtc_timepart.Rd +++ b/man/dtc_timepart.Rd @@ -23,47 +23,33 @@ The time part is extracted from an ISO 8601 date/time variable. By default, partial or missing times are set to NA, and seconds are ignored and not extracted. } -\keyword{"",} -\keyword{"12",} -\keyword{"12:30")} -\keyword{"12:30",} -\keyword{"12:30:59")} -\keyword{"2021-12-25",} -\keyword{"2021-12-25T12",} -\keyword{"2021-12-25T12:30",} -\keyword{"2021-12-25T12:30:59")} -\keyword{"2021-12-25T12:30:59"),} -\keyword{#} -\keyword{##} -\keyword{)} -\keyword{=} -\keyword{Do} -\keyword{FALSE} -\keyword{FALSE,} -\keyword{NA} -\keyword{NA,} -\keyword{Partial} -\keyword{Prevent} -\keyword{and} -\keyword{being} -\keyword{by} -\keyword{c(NA,} -\keyword{default} -\keyword{from} -\keyword{ignore} -\keyword{ignore_seconds} -\keyword{ignored} +\examples{ +## Partial or missing times set to NA and seconds ignored by default +sdtm.oak:::dtc_timepart( + c(NA, "", "2021-12-25", "2021-12-25T12", "2021-12-25T12:30", "2021-12-25T12:30:59") +) +# |--> c(NA, NA, NA, NA, "12:30", "12:30") + +## Prevent partial or missing times from being set to NA +sdtm.oak:::dtc_timepart( + c(NA, "", "2021-12-25", "2021-12-25T12", "2021-12-25T12:30", "2021-12-25T12:30:59"), + partial_as_na = FALSE +) +# |--> c(NA, "", "", "12", "12:30", "12:30") + +## Do not ignore seconds, partial or missing times set to NA +sdtm.oak:::dtc_timepart( + c(NA, "", "2021-12-25", "2021-12-25T12", "2021-12-25T12:30", "2021-12-25T12:30:59"), + ignore_seconds = FALSE +) +# |--> c(NA, NA, NA, NA, NA, "12:30:59") + +## Do not ignore seconds and prevent partial or missing times from being set to NA +sdtm.oak:::dtc_timepart( + c(NA, "", "2021-12-25", "2021-12-25T12", "2021-12-25T12:30", "2021-12-25T12:30:59"), + partial_as_na = FALSE, + ignore_seconds = FALSE +) +# |--> c(NA, "", "", "12", "12:30", "12:30:59") +} \keyword{internal} -\keyword{missing} -\keyword{not} -\keyword{or} -\keyword{partial} -\keyword{partial_as_na} -\keyword{prevent} -\keyword{sdtm.oak:::dtc_timepart(} -\keyword{seconds} -\keyword{seconds,} -\keyword{set} -\keyword{times} -\keyword{to} -\keyword{|-->}