Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace base messages with rlang and cli #76

Merged
merged 4 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Generated by roxygen2: do not edit by hand

S3method(ctl_new_rowid_pillar,cnd_df)
S3method(mutate,cnd_df)
S3method(print,iso8601)
S3method(tbl_sum,cnd_df)
export("%.>%")
Expand Down
2 changes: 1 addition & 1 deletion R/cnd_df.R
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ condition_add <- function(dat, ..., .na = NA, .dat2 = rlang::env()) {
#'
#' @inheritParams dplyr::mutate
#' @importFrom dplyr mutate
#' @export
#' @keywords internal
mutate.cnd_df <- function(.data,
...,
.by = NULL,
Expand Down
9 changes: 2 additions & 7 deletions R/ct.R
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ ct_map <-
#' read_ct_spec(file = path)
#'
#' @export
read_ct_spec <- function(file = stop("`file` must be specified")) {
read_ct_spec <- function(file = rlang::abort("`file` must be specified")) {
ct_spec <- utils::read.csv(file = file, na.strings = c("NA", ""), colClasses = "character") |>
tibble::as_tibble()
assert_ct_spec(ct_spec)
Expand Down Expand Up @@ -327,12 +327,7 @@ ct_spec_example <- function(example) {
local_path <- system.file(path, package = "sdtm.oak")

if (identical(local_path, "")) {
stop(
stringr::str_glue(
"'{example}' does not match any ct spec files. Run `ct_spec_example()` for options."
),
call. = FALSE
)
cli::cli_abort("'{example}' does not match any ct spec files. Run `ct_spec_example()` for options.", call = NULL)
} else {
local_path <-
system.file(path, package = "sdtm.oak", mustWork = TRUE)
Expand Down
12 changes: 5 additions & 7 deletions R/derive_blfl.R
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ derive_blfl <- function(sdtm_in,
))

if (nrow(ds_mod) == 0L) {
stop(paste0(
rlang::abort(paste0(
"No rows for which both --ORRES is not missing\n and --STAT not equals to NOT DONE.\n",
" Not able to derive Baseline Flag or Last Observation Before Exposure Flag"
))
Expand Down Expand Up @@ -428,7 +428,7 @@ derive_blfl <- function(sdtm_in,
ds_base <- dplyr::arrange_at(ds_base, c("USUBJID", con_col))

if (nrow(ds_base) == 0L) {
message(paste0("There are no baseline records."))
rlang::inform("There are no baseline records.")
}

# Group by USUBJID and --TESTCD and filter on the rows that have max value
Expand Down Expand Up @@ -466,12 +466,10 @@ derive_blfl <- function(sdtm_in,

# Assert that merged data frame has same number of rows as input data frame
if (nrow(ds_out) != nrow(sdtm_in)) {
stop(sprintf(
cli::cli_abort(
"Internal error: The processed dataset was expected to have the same
number of rows (%d) as the input dataset (sdtm_in), but it actually has %d rows.",
nrow(sdtm_in),
nrow(ds_out)
))
number of rows ({nrow(sdtm_in)}) as the input dataset (sdtm_in), but it actually has {nrow(ds_out)} rows."
)
}

return(ds_out)
Expand Down
42 changes: 25 additions & 17 deletions R/derive_study_day.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,11 @@ derive_study_day <- function(sdtm_in,
assertthat::assert_that(is.character(study_day_var))
# check tgdt and study_day_var matching, for example, CMSTDTC matches CMSTDY
if (gsub("DTC", "", tgdt, fixed = TRUE) != gsub("DY", "", study_day_var, fixed = TRUE)) {
warning(
"Target date and the returned study day doesn't match. ",
"Expecting matching date and study day, for example, CMENDTC and CMENDY"
rlang::warn(
paste(
"Target date and the returned study day doesn't match.",
"Expecting matching date and study day, for example, CMENDTC and CMENDY"
)
)
}

Expand All @@ -77,10 +79,12 @@ derive_study_day <- function(sdtm_in,
dplyr::group_by(dplyr::pick({{ merge_key }})) |>
dplyr::filter(dplyr::n() > 1L)
if (nrow(check_refdt_uniqueness) > 0L) {
warning(
"Reference date is not unique for each patient! ",
"Patient without unique reference date will be ingored. ",
"NA will be returned for such records."
rlang::warn(
paste(
"Reference date is not unique for each patient!",
"Patient without unique reference date will be ingored.",
"NA will be returned for such records."
)
)
dm_domain <- dm_domain[
!dm_domain[[merge_key]] %in% check_refdt_uniqueness[[merge_key]],
Expand All @@ -102,23 +106,27 @@ derive_study_day <- function(sdtm_in,
sdtm_in[[refdt]] <- tryCatch(
as.Date(sdtm_in[[refdt]], "%Y-%m-%d"),
error = function(e) {
warning(
"Encountered errors when converting refdt to dates. ",
"The warning message is ",
e$message,
call. = FALSE
rlang::warn(
paste(
"Encountered errors when converting refdt to dates.",
"The warning message is",
e$message
),
call = NULL
)
sdtm_in[[refdt]]
}
)
sdtm_in[[tgdt]] <- tryCatch(
as.Date(sdtm_in[[tgdt]], "%Y-%m-%d"),
error = function(e) {
warning(
"Encountered errors when converting tgdt to dates. ",
"The warning message is ",
e$message,
call. = FALSE
rlang::warn(
paste(
"Encountered errors when converting tgdt to dates.",
"The warning message is",
e$message
),
call = NULL
)
sdtm_in[[tgdt]]
}
Expand Down
8 changes: 3 additions & 5 deletions R/domain_example.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,9 @@ domain_example <- function(example) {
local_path <- system.file(path, package = "sdtm.oak")

if (identical(local_path, "")) {
stop(
stringr::str_glue(
"'{example}' does not match any domain example files. Run `domain_example()` for options."
),
call. = FALSE
cli::cli_abort(
"'{example}' does not match any domain example files. Run `domain_example()` for options.",
call = NULL
)
} else {
local_path <-
Expand Down
2 changes: 1 addition & 1 deletion man/mutate.cnd_df.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/read_ct_spec.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
6 changes: 6 additions & 0 deletions vignettes/articles/cnd_df.Rmd → vignettes/cnd_df.Rmd
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
---
title: "Conditioned Data Frames"
output:
rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Conditioned Data Frames}
%\VignetteEncoding{UTF-8}
%\VignetteEngine{knitr::rmarkdown}
---

```{r setup, include=FALSE}
Expand Down
File renamed without changes.
File renamed without changes.
6 changes: 6 additions & 0 deletions vignettes/articles/iso_8601.Rmd → vignettes/iso_8601.Rmd
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
---
title: "Converting dates, times or date-times to ISO 8601"
output:
rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Converting dates, times or date-times to ISO 8601}
%\VignetteEncoding{UTF-8}
%\VignetteEngine{knitr::rmarkdown}
---

```{r, include = FALSE}
Expand Down
File renamed without changes.
Loading