From 34c07f435050b7bd1df0f5bc16791a5e7d50383a Mon Sep 17 00:00:00 2001 From: Abinaya Yogasekaram <73252787+ayogasekaram@users.noreply.github.com> Date: Fri, 8 Nov 2024 12:22:41 -0500 Subject: [PATCH] add error message for class "difftime" (#232) closes #215 Adding an error message for now for clarity - we can revisit supporting the "difftime" class type based on user requests. --- NEWS.md | 1 + R/rlistings.R | 4 ++++ tests/testthat/test-listings.R | 14 ++++++++++++++ 3 files changed, 19 insertions(+) diff --git a/NEWS.md b/NEWS.md index f0a3730c..94cf1c75 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,5 @@ ## rlistings 0.2.9.9008 + * Added an error message for listings with variables of `difftime` class. ## rlistings 0.2.9 * Added `truetype` font support based on new `formatters` api, by @gmbecker. diff --git a/R/rlistings.R b/R/rlistings.R index 11be12e4..04d43d10 100644 --- a/R/rlistings.R +++ b/R/rlistings.R @@ -168,6 +168,10 @@ as_listing <- function(df, ) } + if (any(sapply(df, inherits, "difftime"))) { + stop("One or more variables in the dataframe have class 'difftime'. Please convert to factor or character.") + } + df <- as_tibble(df) varlabs <- var_labels(df, fill = TRUE) o <- do.call(order, df[key_cols]) diff --git a/tests/testthat/test-listings.R b/tests/testthat/test-listings.R index 125f7da8..4f463723 100644 --- a/tests/testthat/test-listings.R +++ b/tests/testthat/test-listings.R @@ -350,3 +350,17 @@ testthat::test_that("split_into_pages_by_var works as expected", { ) testthat::expect_identical(lsting, lsting_id) }) + +testthat::test_that("appropriate error message returned for 'difftime' class", { + tmp_data <- ex_adae[1:100, ] + class(tmp_data$study_duration_secs) <- "difftime" + + testthat::expect_error(as_listing( + tmp_data, + key_cols = c("USUBJID", "AGE"), + disp_cols = "study_duration_secs", + main_title = "title", + main_footer = "foot" + ) %>% + split_into_pages_by_var("SEX", page_prefix = "Patient Subset - Sex")) +})