Skip to content

Commit

Permalink
add error message for class "difftime" (#232)
Browse files Browse the repository at this point in the history
closes #215 

Adding an error message for now for clarity - we can revisit supporting
the "difftime" class type based on user requests.
  • Loading branch information
ayogasekaram authored Nov 8, 2024
1 parent f6bb1fb commit 34c07f4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
4 changes: 4 additions & 0 deletions R/rlistings.R
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
14 changes: 14 additions & 0 deletions tests/testthat/test-listings.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
})

0 comments on commit 34c07f4

Please sign in to comment.