Skip to content

Commit

Permalink
Merge branch 'main' into 952_coxreg_pagination@main
Browse files Browse the repository at this point in the history
  • Loading branch information
Melkiades authored Jun 9, 2023
2 parents 7cdd313 + 12b8b42 commit 0917561
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 42 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: tern
Title: Create Common TLGs Used in Clinical Trials
Version: 0.8.2.9007
Date: 2023-06-08
Version: 0.8.2.9008
Date: 2023-06-09
Authors@R: c(
person("Joe", "Zhu", , "[email protected]", role = c("aut", "cre")),
person("Daniel", "Sabanés Bové", , "[email protected]", role = "aut"),
Expand Down
13 changes: 8 additions & 5 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
# tern 0.8.2.9007
# tern 0.8.2.9008

### Enhancements
* Added explicit zero counts to `g_km` plot "at risk" annotation tables.
* Added a flag for total level split in `analyze_patients_exposure_in_cols`.
* Implemented `.indent_mods` argument in functions `h_tab_one_biomarker`, `h_tab_rsp_one_biomarker`, `h_tab_surv_one_biomarker`, `summarize_logistic`, `logistic_summary_by_flag`, `tabulate_rsp_biomarkers`, a_coxreg, `summarize_coxreg`, `tabulate_survival_biomarkers`, `surv_time`, `surv_timepoint`, and `cfun_by_flag`.
* Updated `summarize_coxreg` to print covariates in data rows for univariate Cox regression with no interactions and content rows otherwise.

### Bug Fixes
* Fixed bug in `split_text_grob` preventing titles and footnotes from being properly formatted and printed by `decorate_grob`.

### Miscellaneous
* Updated README to include installation instructions for CRAN.
* Began deprecation of `indent_mod` argument and replace it with the `.indent_mods` argument in `summarize_num_patients` and `analyze_num_patients`.
Expand All @@ -15,10 +18,6 @@
### Breaking Changes
* Refactored `s_coxreg` and `summarize_coxreg`to work with new analysis function `a_coxreg`.

### Bug Fixes
* Fixed missing label for `TRTEDTM` in `tern` datasets.
* Fixed improper implementation of `na_level` argument in `summarize_vars` preventing it from having an effect.

### Enhancements
* Added `section_div` and `na_level` arguments to `summarize_vars`.
* Added `median_range` as a numeric variable statistic option for `summarize_vars`.
Expand All @@ -30,6 +29,10 @@
* Updated `s_summary` and `s_compare` to allow `NA` values in input variables. For factor variables with `NA`s, if `na.rm = FALSE` an explicit `NA` level will be automatically added. `na.rm = TRUE` will also consider `"<Missing>"` values and exclude them.
* Updated purpose of `na_level` parameter in `s_summary` and `s_compare` to align with other `tern` functions. Instead of being a string to consider as `NA` when setting `na.rm = TRUE`, it now defines a string to print in place of `NA` values in the output table.

### Bug Fixes
* Fixed missing label for `TRTEDTM` in `tern` datasets.
* Fixed improper implementation of `na_level` argument in `summarize_vars` preventing it from having an effect.

### Miscellaneous
* Implemented the `lubridate` package for date variables in `tern` datasets.
* Organized `.gitignore` and `.Rbuildignore` files.
Expand Down
66 changes: 32 additions & 34 deletions R/decorate_grob.R
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ decorate_grob <- function(grob,
titles,
footnotes,
page = "",
width_titles = grid::unit(1, "npc"),
width_titles = grid::unit(1, "npc") - grid::stringWidth(page),
width_footnotes = grid::unit(1, "npc") - grid::stringWidth(page),
border = TRUE,
margins = grid::unit(c(1, 0, 1, 0), "lines"),
Expand Down Expand Up @@ -266,30 +266,32 @@ heightDetails.decoratedGrob <- function(x) {
# Adapted from Paul Murell R Graphics 2nd Edition
# https://www.stat.auckland.ac.nz/~paul/RG2e/interactgrid-splittext.R
split_string <- function(text, width) {
availwidth <- grid::convertWidth(width, "in", valueOnly = TRUE)
textwidth <- grid::convertWidth(grid::stringWidth(text), "in", valueOnly = TRUE)
strings <- strsplit(text, " ")[[1]]

if (textwidth <= availwidth || length(strings) == 1) {
text
} else {
strings <- strsplit(text, " ")
out_string <- NA
for (string_i in seq_along(strings)) {
newline_str <- strings[[string_i]]
if (length(newline_str) == 0) newline_str <- ""
if (is.na(out_string[string_i])) {
out_string[string_i] <- newline_str[[1]][[1]]
linewidth <- grid::stringWidth(out_string[string_i])
}
gapwidth <- grid::stringWidth(" ")
newstring <- strings[1]
linewidth <- grid::stringWidth(newstring)

for (i in 2:length(strings)) {
str_width <- grid::stringWidth(strings[i])
if (grid::convertWidth(linewidth + gapwidth + str_width, "in", valueOnly = TRUE) < availwidth) {
sep <- " "
linewidth <- linewidth + gapwidth + str_width
} else {
sep <- "\n"
linewidth <- str_width
availwidth <- as.numeric(width)
if (length(newline_str) > 1) {
for (i in seq(2, length(newline_str))) {
width_i <- grid::stringWidth(newline_str[i])
if (grid::convertWidth(linewidth + gapwidth + width_i, grid::unitType(width), valueOnly = TRUE) < availwidth) {
sep <- " "
linewidth <- linewidth + gapwidth + width_i
} else {
sep <- "\n"
linewidth <- width_i
}
out_string[string_i] <- paste(out_string[string_i], newline_str[i], sep = sep)
}
newstring <- paste(newstring, strings[i], sep = sep)
}
newstring
}
paste(out_string, collapse = "\n")
}

#' Split Text According To Available Text Width
Expand Down Expand Up @@ -354,15 +356,12 @@ split_text_grob <- function(text,
name = NULL,
gp = grid::gpar(),
vp = NULL) {
if (!grid::is.unit(x)) {
x <- grid::unit(x, default.units)
}
if (!grid::is.unit(y)) {
y <- grid::unit(y, default.units)
}

checkmate::assert_true(grid::is.unit(width))
checkmate::assert_vector(width, len = 1)
if (!grid::is.unit(x)) x <- grid::unit(x, default.units)
if (!grid::is.unit(y)) y <- grid::unit(y, default.units)
if (!grid::is.unit(width)) width <- grid::unit(width, default.units)
if (grid::unitType(x) %in% c("sum", "min", "max")) x <- grid::convertUnit(x, default.units)
if (grid::unitType(y) %in% c("sum", "min", "max")) y <- grid::convertUnit(y, default.units)
if (grid::unitType(width) %in% c("sum", "min", "max")) width <- grid::convertUnit(width, default.units)

## if it is a fixed unit then we do not need to recalculate when viewport resized
if (!inherits(width, "unit.arithmetic") &&
Expand All @@ -371,10 +370,9 @@ split_text_grob <- function(text,
attr(text, "fixed_text") <- paste(vapply(text, split_string, character(1), width = width), collapse = "\n")
}

grid::grob(
text = text,
grid::grid.text(
label = split_string(text, width),
x = x, y = y,
width = width,
just = just,
hjust = hjust,
vjust = vjust,
Expand All @@ -383,7 +381,7 @@ split_text_grob <- function(text,
name = name,
gp = gp,
vp = vp,
cl = "dynamicSplitText"
draw = FALSE
)
}

Expand Down
2 changes: 1 addition & 1 deletion man/decorate_grob.Rd

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

0 comments on commit 0917561

Please sign in to comment.