Skip to content

Commit

Permalink
Revert "Merge branch 'main' into wasm-poc"
Browse files Browse the repository at this point in the history
This reverts commit 21c7639, reversing
changes made to b6e6c86.
  • Loading branch information
walkowif committed Jun 20, 2024
1 parent b19e286 commit 1ef030d
Show file tree
Hide file tree
Showing 19 changed files with 262 additions and 779 deletions.
8 changes: 4 additions & 4 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.9.4.9010
Date: 2024-06-16
Version: 0.9.4.9007
Date: 2024-05-14
Authors@R: c(
person("Joe", "Zhu", , "[email protected]", role = c("aut", "cre")),
person("Daniel", "Sabanés Bové", , "[email protected]", role = "aut"),
Expand All @@ -25,7 +25,7 @@ URL: https://insightsengineering.github.io/tern/,
BugReports: https://github.com/insightsengineering/tern/issues
Depends:
R (>= 3.6),
rtables (>= 0.6.7.9004)
rtables (>= 0.6.7)
Imports:
broom (>= 0.5.4),
car (>= 3.0-13),
Expand All @@ -34,7 +34,7 @@ Imports:
dplyr (>= 1.0.0),
emmeans (>= 1.8.0),
forcats (>= 1.0.0),
formatters (>= 0.5.7.9000),
formatters (>= 0.5.6),
ggplot2 (>= 3.5.0),
grid,
gridExtra (>= 2.0.0),
Expand Down
6 changes: 2 additions & 4 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
# tern 0.9.4.9010
# tern 0.9.4.9007

### Enhancements
* Added `facet_var` to `g_lineplot` to allow plot faceting by a factor variable.
* Updated `g_lineplot` legend to follow factor levels set by users.
* Added examples and tests for `label_all` parameter to `extract_survival_biomarkers` and `extract_survival_subgroups`.
* Added the `xticks`, `xlim`, and `ylim` arguments to `g_lineplot` to allow for customization of the x and y axes.

### Bug Fixes
* Fixed bug in `s_ancova` that prevented statistics from being printed when arm levels include special characters.
* Fixed bug in `decorate_grob` that prevented the right margins to be respected when adding title and footers decorations.

### Miscellaneous
* Began deprecation of the unused `label_all` parameter to `tabulate_survival_biomarkers` and `tabulate_survival_subgroups`, with redirection to the same parameter in their associated `extract_*` functions.
Expand Down Expand Up @@ -36,7 +34,7 @@
### Miscellaneous
* Added function `expect_snapshot_ggplot` to test setup file to process plot snapshot tests and allow plot dimensions to be set.
* Adapted to argument renames introduced in `ggplot2` 3.5.0.
* Renamed `individual_patient_plot.R` to `g_ipp.R`.
* Renamed `individual_patient_plot.R` to `g_ipp.R`.
* Removed all instances of deprecated parameters `time_unit_input`, `time_unit_output`, `na_level` and `indent_mod`.
* Removed deprecated functions `summarize_vars`, `control_summarize_vars`, `a_compare`, `create_afun_summary`, `create_afun_compare`, and `summary_custom`.
* Removed `vdiffr` package from Suggests in DESCRIPTION file.
Expand Down
5 changes: 0 additions & 5 deletions R/argument_convention.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,6 @@
#' @param vars (`character`)\cr variable names for the primary analysis variable to be iterated over.
#' @param var (`string`)\cr single variable name for the primary analysis variable.
#' @param x (`numeric`)\cr vector of numbers we want to analyze.
#' @param xlim (`numeric(2)`)\cr vector containing lower and upper limits for the x-axis, respectively.
#' If `NULL` (default), the default scale range is used.
#' @param ylim (`numeric(2)`)\cr vector containing lower and upper limits for the y-axis, respectively.
#' If `NULL` (default), the default scale range is used.
#'
#'
#' @details Although this function just returns `NULL` it has two uses, for
#' the `tern` users it provides a documentation of arguments that are
Expand Down
74 changes: 29 additions & 45 deletions R/decorate_grob.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,14 @@
#' according to the page width.
#' @param footnotes (`character`)\cr footnotes. Uses the same formatting rules as `titles`.
#' @param page (`string` or `NULL`)\cr page numeration. If `NULL` then no page number is displayed.
#' @param width_titles (`grid::unit`)\cr width of titles. Usually defined as all the available space
#' `grid::unit(1, "npc")`, it is affected by the parameter `outer_margins`. Right margins (`outer_margins[4]`)
#' need to be subtracted to the allowed width.
#' @param width_footnotes (`grid::unit`)\cr width of footnotes. Same default and margin correction as `width_titles`.
#' @param width_titles (`grid::unit`)\cr width of titles.
#' @param width_footnotes (`grid::unit`)\cr width of footnotes.
#' @param border (`flag`)\cr whether a border should be drawn around the plot or not.
#' @param padding (`grid::unit`)\cr padding. A unit object of length 4. Innermost margin between the plot (`grob`)
#' and, possibly, the border of the plot. Usually expressed in 4 identical values (usually `"lines"`). It defaults
#' to `grid::unit(rep(1, 4), "lines")`.
#' @param margins (`grid::unit`)\cr margins. A unit object of length 4. Margins between the plot and the other
#' elements in the list (e.g. titles, plot, and footers). This is usually expressed in 4 `"lines"`, where the
#' lateral ones are 0s, while top and bottom are 1s. It defaults to `grid::unit(c(1, 0, 1, 0), "lines")`.
#' @param outer_margins (`grid::unit`)\cr outer margins. A unit object of length 4. It defines the general margin of
#' the plot, considering also decorations like titles, footnotes, and page numbers. It defaults to
#' `grid::unit(c(2, 1.5, 3, 1.5), "cm")`.
#' @param gp_titles (`gpar`)\cr a `gpar` object. Mainly used to set different `"fontsize"`.
#' @param gp_footnotes (`gpar`)\cr a `gpar` object. Mainly used to set different `"fontsize"`.
#' @param margins (`grid::unit`)\cr margins. A unit object of length 4.
#' @param padding (`grid::unit`)\cr padding. A unit object of length 4.
#' @param outer_margins (`grid::unit`)\cr outer margins. A unit object of length 4.
#' @param gp_titles (`gpar`)\cr a `gpar` object.
#' @param gp_footnotes (`gpar`)\cr a `gpar` object.
#'
#' @return A grid grob (`gTree`).
#'
Expand Down Expand Up @@ -140,24 +132,17 @@ decorate_grob <- function(grob,
titles,
footnotes,
page = "",
width_titles = grid::unit(1, "npc"),
width_footnotes = grid::unit(1, "npc"),
width_titles = grid::unit(1, "npc") - grid::unit(1.5, "cm"),
width_footnotes = grid::unit(1, "npc") - grid::unit(1.5, "cm"),
border = TRUE,
padding = grid::unit(rep(1, 4), "lines"),
margins = grid::unit(c(1, 0, 1, 0), "lines"),
padding = grid::unit(rep(1, 4), "lines"),
outer_margins = grid::unit(c(2, 1.5, 3, 1.5), "cm"),
gp_titles = grid::gpar(),
gp_footnotes = grid::gpar(fontsize = 8),
name = NULL,
gp = grid::gpar(),
vp = NULL) {
# External margins need to be taken into account when defining the width of titles and footers
# because the text is split in advance depending on only the width of the viewport.
if (any(as.numeric(outer_margins) > 0)) {
width_titles <- width_titles - outer_margins[4]
width_footnotes <- width_footnotes - outer_margins[4]
}

st_titles <- split_text_grob(
titles,
x = 0, y = 1,
Expand All @@ -184,45 +169,45 @@ decorate_grob <- function(grob,
gp = gp_footnotes
)

# Initial decoration of the grob -> border, paddings, and margins are used here
main_plot <- grid::gTree(
children = grid::gList(
if (border) grid::rectGrob(),
grid::gTree(
children = grid::gList(
grob
),
vp = grid::plotViewport(margins = padding) # innermost margins of the grob plot
)
),
vp = grid::vpStack(
grid::viewport(layout.pos.row = 2, layout.pos.col = 1),
grid::plotViewport(margins = margins) # margins around the border plot
)
)

grid::gTree(
grob = grob,
titles = titles,
footnotes = footnotes,
page = page,
width_titles = width_titles,
width_footnotes = width_footnotes,
border = border,
margins = margins,
padding = padding,
outer_margins = outer_margins,
gp_titles = gp_titles,
gp_footnotes = gp_footnotes,
children = grid::gList(
grid::gTree(
children = grid::gList(
st_titles,
main_plot, # main plot with border, padding, and margins
grid::gTree(
children = grid::gList(
if (border) grid::rectGrob(),
grid::gTree(
children = grid::gList(
grob
),
vp = grid::plotViewport(margins = padding)
)
),
vp = grid::vpStack(
grid::viewport(layout.pos.row = 2, layout.pos.col = 1),
grid::plotViewport(margins = margins)
)
),
st_footnotes,
pg_footnote
),
childrenvp = NULL,
name = "titles_grob_footnotes",
vp = grid::vpStack(
grid::plotViewport(margins = outer_margins), # Main external margins
grid::plotViewport(margins = outer_margins),
grid::viewport(
layout = grid::grid.layout(
nrow = 4, ncol = 1,
Expand Down Expand Up @@ -400,7 +385,6 @@ split_string <- function(text, width) {
if (length(newline_str) > 1) {
for (i in seq(2, length(newline_str))) {
width_i <- grid::stringWidth(newline_str[i])
# Main conversion of allowed text width -> npc units are 0<npc<1. External viewport is used for conversion
if (grid::convertWidth(linewidth + gapwidth + width_i, grid::unitType(width), valueOnly = TRUE) < availwidth) {
sep <- " "
linewidth <- linewidth + gapwidth + width_i
Expand Down
4 changes: 3 additions & 1 deletion R/g_km.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#' including the number of patient at risk at given time and the median survival
#' per group.
#'
#' @inheritParams argument_convention
#' @param df (`data.frame`)\cr data set containing all analysis variables.
#' @param variables (named `list`)\cr variable names. Details are:
#' * `tte` (`numeric`)\cr variable indicating time-to-event duration values.
#' * `is_event` (`logical`)\cr event variable. `TRUE` if event, `FALSE` if time to event is censored.
Expand Down Expand Up @@ -35,6 +35,8 @@
#' @param yval (`string`)\cr type of plot, to be plotted on the y-axis. Options are `Survival` (default) and `Failure`
#' probability.
#' @param ylab (`string`)\cr y-axis label.
#' @param ylim (`numeric(2)`)\cr vector containing lower and upper limits for the y-axis, respectively.
#' If `NULL` (default), the minimum and maximum y-values displayed are used as limits.
#' @param title (`string`)\cr plot title.
#' @param footnotes (`string`)\cr plot footnotes.
#' @param font_size (`numeric(1)`)\cr font size to use for all text.
Expand Down
19 changes: 3 additions & 16 deletions R/g_lineplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#'
#' Line plot with the optional table.
#'
#' @inheritParams argument_convention
#' @param df (`data.frame`)\cr data set containing all analysis variables.
#' @param alt_counts_df (`data.frame` or `NULL`)\cr data set that will be used (only)
#' to counts objects in groups for stratification.
#' @param variables (named `character`) vector of variable names in `df` which should include:
Expand Down Expand Up @@ -46,9 +46,6 @@
#' @param legend_position (`string`)\cr the position of the plot legend (`"none"`, `"left"`, `"right"`, `"bottom"`,
#' `"top"`, or a two-element numeric vector).
#' @param ggtheme (`theme`)\cr a graphical theme as provided by `ggplot2` to control styling of the plot.
#' @param xticks (`numeric` or `NULL`)\cr numeric vector of tick positions or a single number with spacing
#' between ticks on the x-axis, for use when `variables$x` is numeric. If `NULL` (default), [labeling::extended()] is
#' used to determine optimal tick positions on the x-axis. If `variables$x` is not numeric, this argument is ignored.
#' @param x_lab (`string` or `NULL`)\cr x-axis label. If `NULL` then no label will be added.
#' @param y_lab (`string` or `NULL`)\cr y-axis label. If `NULL` then no label will be added.
#' @param y_lab_add_paramcd (`flag`)\cr whether `paramcd`, i.e. `unique(df[[variables["paramcd"]]])` should be added
Expand Down Expand Up @@ -143,9 +140,6 @@ g_lineplot <- function(df,
legend_title = NULL,
legend_position = "bottom",
ggtheme = nestcolor::theme_nest(),
xticks = NULL,
xlim = NULL,
ylim = NULL,
x_lab = obj_label(df[[variables[["x"]]]]),
y_lab = NULL,
y_lab_add_paramcd = TRUE,
Expand All @@ -164,9 +158,7 @@ g_lineplot <- function(df,
checkmate::assert_character(mid, null.ok = TRUE)
checkmate::assert_character(interval, null.ok = TRUE)
checkmate::assert_character(col, null.ok = TRUE)
checkmate::assert_numeric(xticks, null.ok = TRUE)
checkmate::assert_numeric(xlim, finite = TRUE, any.missing = FALSE, len = 2, sorted = TRUE, null.ok = TRUE)
checkmate::assert_numeric(ylim, finite = TRUE, any.missing = FALSE, len = 2, sorted = TRUE, null.ok = TRUE)

checkmate::assert_string(title, null.ok = TRUE)
checkmate::assert_string(subtitle, null.ok = TRUE)

Expand Down Expand Up @@ -361,13 +353,8 @@ g_lineplot <- function(df,
}
}

if (is.numeric(df_stats[[x]])) {
if (length(xticks) == 1) xticks <- seq(from = min(df_stats[[x]]), to = max(df_stats[[x]]), by = xticks)
p <- p + ggplot2::scale_x_continuous(breaks = if (!is.null(xticks)) xticks else waiver(), limits = xlim)
}

p <- p +
ggplot2::scale_y_continuous(labels = scales::comma, limits = ylim) +
ggplot2::scale_y_continuous(labels = scales::comma) +
ggplot2::labs(
title = title,
subtitle = subtitle,
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Data visualizations:
- Kaplan-Meier plots ([`g_km`](https://insightsengineering.github.io/tern/latest-tag/reference/g_km.html))
- Forest plots ([`g_forest`](https://insightsengineering.github.io/tern/latest-tag/reference/g_forest.html))
- STEP graphs ([`g_step`](https://insightsengineering.github.io/tern/latest-tag/reference/g_step.html))
- Individual patient plots ([`g_ipp`](https://insightsengineering.github.io/tern/latest-tag/reference/g_ipp.html))
- Individual patient plots ([`g_ipp`](https://insightsengineering.github.io/tern/latest-tag/reference/individual_patient_plot.html))
- Waterfall plots ([`g_waterfall`](https://insightsengineering.github.io/tern/latest-tag/reference/g_waterfall.html))

Statistical model fit summaries:
Expand Down
2 changes: 0 additions & 2 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ ADTTE
AE
ANCOVA
Agresti
Bové
Byar's
CDISC
CMH
Expand All @@ -27,7 +26,6 @@ Newcombe
Pre
Rua
SMQ
Sabanés
Satterthwaite
Schouten
TLG
Expand Down
6 changes: 0 additions & 6 deletions man/argument_convention.Rd

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

28 changes: 10 additions & 18 deletions man/decorate_grob.Rd

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

2 changes: 1 addition & 1 deletion man/g_km.Rd

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

13 changes: 0 additions & 13 deletions man/g_lineplot.Rd

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

Loading

0 comments on commit 1ef030d

Please sign in to comment.