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

add error message for class "difftime" #232

Merged
merged 4 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all 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: 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"))
})
Loading