-
-
Notifications
You must be signed in to change notification settings - Fork 7
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Summary
Long values in the table that cause wrapping issues make formatters::export_as_pdf fail the export with the following message:
========= COLUMN-WISE: Checking possible pagination for page 1
-> Attempting pagination between 1 and 4 column
FAIL: selected 4 columns require 69 chars, while only 95 are available
.
details: [raw: 57 chars (4 cols), rep. cols: 0 chars (0 cols), t
ot. colgap: 12 chars].
-> Attempting pagination between 1 and 3 column
FAIL: selected 3 columns require 51 chars, while only 95 are available
.
details: [raw: 42 chars (3 cols), rep. cols: 0 chars (0 cols), t
ot. colgap: 9 chars].
-> Attempting pagination between 1 and 2 column
FAIL: selected 2 columns require 34 chars, while only 95 are available
.
details: [raw: 28 chars (2 cols), rep. cols: 0 chars (0 cols), t
ot. colgap: 6 chars].
-> Attempting pagination between 1 and 1 column
FAIL: selected 1 columns require 17 chars, while only 95 are available
.
details: [raw: 14 chars (1 cols), rep. cols: 0 chars (0 cols), t
ot. colgap: 3 chars].
Error in find_pag(pagdf = pagdf, current_page = current_page, start = st
art, :
-------------------------------------- Error Summary -----------------
-----------------------
Unable to find any valid pagination split for page 1 between columns 1 a
nd 4.
Inserted cpp (column-space, content per page) : 95
Context-relevant additional fixed column characters: 82
Check the minimum allowed column characters per page in the last FAIL(ed
) attempt.
Note: take a look at the last FAIL(ed) attempt above to see what went wr
ong. It could be, for example, that the inserted column width induces so
me wrapping, hence the inserted number of lines (lpp) is not enough.
The problem is mainly in the error message (as I understand it might be impossible to export this table to a pdf):
- the wording is confusing, e.g.
FAIL: selected 4 columns require 69 chars, while only 95 are availablesuggests everything is fine (there's more available characters that 4 columns require!), but I guess it's not - the changes in the line per page do nothing to alleviate this issue, I would expect the message to indicate that there is a wrapping issue with the values in the table and it's basically impossible to generate this pdf
A reproducible example (not minimal, but showcases the problem and uses synthetic data)
library(teal.modules.clinical)
# Create synthetic data
set.seed(123)
n_patients <- 50
n_medications <- 100
# Create synthetic ADSL
ADSL <- data.frame(
STUDYID = rep("STUDY1", n_patients),
USUBJID = paste0("SUBJ", 1:n_patients),
TRT01A = factor(sample(c("Treatment A", "Treatment B", "Treatment C"), n_patients, replace = TRUE))
)
# Create synthetic ADCM with long medication names
ADCM <- data.frame(
STUDYID = rep("STUDY1", n_medications),
USUBJID = sample(ADSL$USUBJID, n_medications, replace = TRUE),
CMSEQ = 1:n_medications,
CMLVL1 = factor(sample(c(
"Very Long ATC Level 1 Category Name That Will Cause Wrapping Issues",
"Another Very Long ATC Level 1 Category Name That Will Cause Wrapping Issues"
), n_medications, replace = TRUE)),
CMLVL2 = factor(sample(c(
"Very Long ATC Level 2 Category Name That Will Cause Wrapping Issues",
"Another Very Long ATC Level 2 Category Name That Will Cause Wrapping Issues"
), n_medications, replace = TRUE)),
CMDECOD = factor(sample(c(
"Very Long Standardized Medication Name That Will Cause Wrapping Issues",
"Another Very Long Standardized Medication Name That Will Cause Wrapping Issues"
), n_medications, replace = TRUE))
)
# Rest of the code remains the same
ANL_1 <- ADSL %>% dplyr::select(STUDYID, USUBJID, TRT01A)
ANL_2 <- ADCM %>% dplyr::select(STUDYID, USUBJID, CMSEQ, CMLVL1, CMLVL2, CMDECOD)
ANL <- ANL_1
ANL <- dplyr::inner_join(ANL, ANL_2, by = c("STUDYID", "USUBJID"))
ANL <- ANL %>% teal.data::col_relabel(TRT01A = "Actual Treatment", CMLVL1 = "Preferred ATC Text for ATC Level 1", CMLVL2 = "Preferred ATC Text for ATC Level 2", CMDECOD = "Standardized Medication Name")
ANL_ADSL_1 <- ADSL %>% dplyr::select(STUDYID, USUBJID, TRT01A)
ANL_ADSL <- ANL_ADSL_1
ANL_ADSL <- ANL_ADSL %>% teal.data::col_relabel(TRT01A = "Actual Treatment")
anl <- ANL
anl <- anl %>% dplyr::mutate(TRT01A = droplevels(TRT01A))
arm_levels <- levels(anl[["TRT01A"]])
ANL_ADSL <- ANL_ADSL %>% dplyr::filter(TRT01A %in% arm_levels)
ANL_ADSL <- ANL_ADSL %>% dplyr::mutate(TRT01A = droplevels(TRT01A))
anl <- anl %>% df_explicit_na(omit_columns = setdiff(names(anl), c("CMLVL1", "CMLVL2", "CMDECOD")))
anl <- anl %>% dplyr::mutate(CMSEQ = as.factor(CMSEQ))
ANL_ADSL <- df_explicit_na(ANL_ADSL, na_level = "<Missing>")
split_fun <- drop_split_levels
lyt <- rtables::basic_table(title = "Concomitant Medications by Preferred ATC Text for ATC Level 1, Preferred ATC Text for ATC Level 2 and Standardized Medication Name", show_colcounts = TRUE) %>%
rtables::split_cols_by(var = "TRT01A") %>%
rtables::add_overall_col(label = "All Patients") %>%
summarize_num_patients(var = "USUBJID", count_by = "CMSEQ", .stats = c("unique", "nonunique"), .labels = c(unique = "Total number of patients with at least one medication", nonunique = "Total number of medications")) %>%
rtables::split_rows_by("CMLVL1", child_labels = "visible", nested = FALSE, indent_mod = -1L, split_fun = split_fun, label_pos = "topleft", split_label = teal.data::col_labels(ANL["CMLVL1"])) %>%
rtables::split_rows_by("CMLVL2", child_labels = "visible", nested = TRUE, indent_mod = 0L, split_fun = split_fun, label_pos = "topleft", split_label = teal.data::col_labels(ANL["CMLVL2"])) %>%
summarize_num_patients(var = "USUBJID", count_by = "CMSEQ", .stats = c("unique", "nonunique"), .labels = c(
unique = "Total number of patients with at least one medication",
nonunique = "Total number of medications"
)) %>%
count_occurrences(vars = "CMDECOD", .indent_mods = -1L) %>%
append_varlabels(ANL, "CMDECOD", indent = 2L)
result <- rtables::build_table(lyt = lyt, df = anl, alt_counts_df = ANL_ADSL)
sorted_result <- result %>% sort_at_path(path = c("CMLVL1", "*", "CMLVL2", "*", "CMDECOD"), scorefun = score_occurrences)
table <- sorted_result
tf <- tempfile(fileext = ".pdf")
rtables::export_as_pdf(
table,
paginate = TRUE,
lpp = 500,
file = tf
)R session info
R version 4.4.3 (2025-02-28) -- "Trophy Case"
Copyright (C) 2025 The R Foundation for Statistical Computing
Platform: aarch64-apple-darwin20
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
Natural language support but running in an English locale
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> utils::sessionInfo()
R version 4.4.3 (2025-02-28)
Platform: aarch64-apple-darwin20
Running under: macOS Sequoia 15.4.1
Matrix products: default
BLAS: /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRlapack.dylib; LAPACK version 3.12.0
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
time zone: Europe/Warsaw
tzcode source: internal
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_4.4.3OS / Environment
- MacOS 15.4.1
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working