-
Notifications
You must be signed in to change notification settings - Fork 32
Add exclude_rows argument to g_forest() (Solves #1498).
#1503
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,6 +47,14 @@ | |
| #' is no longer used. | ||
| #' @param newpage `r lifecycle::badge("deprecated")` `g_forest` is now generated as a `ggplot` object. This argument | ||
| #' is no longer used. | ||
| #' @param exclude_rows (`integerish` or `NULL`)\cr vector of positive row | ||
| #' indices specifying rows to exclude from the forest plot. Row indices are | ||
| #' specified relative to [rtables::as_result_df()] applied to `tbl`. Values | ||
| #' must be between 1 and the number of rows in the result data frame, with no | ||
| #' missing values. The specified rows are removed before plotting. This can be | ||
|
wwojciech marked this conversation as resolved.
Outdated
|
||
| #' used to omit rows that should not be displayed in the forest plot, such as | ||
| #' rows containing non-plottable values. Defaults to `NULL`, meaning that all | ||
| #' rows are considered for plotting. | ||
| #' | ||
| #' @return `ggplot` forest plot and table. | ||
| #' | ||
|
|
@@ -77,6 +85,7 @@ | |
| #' tbl <- basic_table() |> | ||
| #' tabulate_rsp_subgroups(df) | ||
| #' g_forest(tbl) | ||
| #' g_forest(tbl, exclude_rows = 1) | ||
| #' | ||
| #' # Odds ratio only table. | ||
| #' | ||
|
|
@@ -177,7 +186,8 @@ g_forest <- function(tbl, | |
| as_list = FALSE, | ||
| gp = lifecycle::deprecated(), | ||
| draw = lifecycle::deprecated(), | ||
| newpage = lifecycle::deprecated()) { | ||
| newpage = lifecycle::deprecated(), | ||
| exclude_rows = NULL) { | ||
| # Deprecated argument warnings | ||
| if (lifecycle::is_present(width_row_names)) { | ||
| lifecycle::deprecate_warn( | ||
|
|
@@ -220,6 +230,10 @@ g_forest <- function(tbl, | |
| checkmate::assert_number(font_size, lower = 0) | ||
| checkmate::assert_character(col, null.ok = TRUE) | ||
| checkmate::assert_true(is.null(col) | length(col) == 1 | length(col) == nrow(tbl)) | ||
| checkmate::assert_integerish( | ||
| exclude_rows, | ||
| lower = 1L, upper = nrow(as_result_df(tbl)), any.missing = FALSE, min.len = 1L, null.ok = TRUE | ||
| ) | ||
|
|
||
| # Extract info from table | ||
| mat <- matrix_form(tbl, indent_rownames = TRUE) | ||
|
|
@@ -241,6 +255,9 @@ g_forest <- function(tbl, | |
| } | ||
|
|
||
| tbl_df <- as_result_df(tbl) | ||
|
wwojciech marked this conversation as resolved.
Outdated
|
||
| if (!is.null(exclude_rows)) { | ||
| tbl_df <- tbl_df[-exclude_rows, ] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do not understand the need of this parameter inside this function when you can add the filtering before the input i.e. doing The rest is fine, it makes the function more stable ^^
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The issue is that using
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It makes sense! sorry I had to double check its behavior again ^^ then it is is good to go! |
||
| } | ||
| dat_cols <- seq(which(names(tbl_df) == "node_class") + 1, ncol(tbl_df)) | ||
| tbl_df <- tbl_df[, c(which(names(tbl_df) == "row_num"), dat_cols)] | ||
| names(tbl_df) <- c("row_num", tbl_stats) | ||
|
|
@@ -252,7 +269,9 @@ g_forest <- function(tbl, | |
| tbl_df[["empty_ci"]] <- rep(list(c(NA_real_, NA_real_)), nrow(tbl_df)) | ||
| ci_col <- which(names(tbl_df) == "empty_ci") | ||
| } | ||
| if (length(tbl_df[, ci_col][[1]]) != 2) stop("CI column must have two elements (lower and upper limits).") | ||
| if (nrow(tbl_df) >= 1 && length(tbl_df[, ci_col][[1]]) != 2) { | ||
| stop("CI column must have two elements (lower and upper limits).") | ||
| } | ||
|
|
||
| if (!is.null(col_x)) { | ||
| x_col <- col_x + 1 | ||
|
|
@@ -278,17 +297,16 @@ g_forest <- function(tbl, | |
| x_labels <- x_at | ||
|
|
||
| # Apply log transformation | ||
| if (logx) { | ||
| if (logx && nrow(tbl_df) >= 1) { | ||
|
wwojciech marked this conversation as resolved.
|
||
| x_t <- log(x) | ||
| lwr_t <- log(lwr) | ||
| upr_t <- log(upr) | ||
| xlim_t <- log(xlim) | ||
| } else { | ||
| x_t <- x | ||
| lwr_t <- lwr | ||
| upr_t <- upr | ||
| xlim_t <- xlim | ||
| } | ||
| xlim_t <- if (logx) log(xlim) else xlim | ||
|
wwojciech marked this conversation as resolved.
|
||
|
|
||
| # Set up plot area | ||
| gg_plt <- ggplot(data = tbl_df) + | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.