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

suppressWarnings() #200

Merged
merged 1 commit into from
Apr 16, 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
6 changes: 3 additions & 3 deletions R/add_censor_mark.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ update_add_censor_mark <- function(p, add_censor_mark_empty_list) {
)

# if a stratified model, add a `colour=` argument
if ("strata" %in% names(ggplot2::ggplot_build(p)$plot$data) &&
if ("strata" %in% names(suppressWarnings(ggplot2::ggplot_build(p))$plot$data) &&
isFALSE(getOption("ggsurvfit.switch-color-linetype", default = FALSE))) {
lst_aes <- c(lst_aes, list(color = rlang::expr(.data$strata)))
}
if ("outcome" %in% names(ggplot2::ggplot_build(p)$plot$data) &&
length(unique(ggplot2::ggplot_build(p)$plot$data$outcome)) > 1L &&
if ("outcome" %in% names(suppressWarnings(ggplot2::ggplot_build(p))$plot$data) &&
length(unique(suppressWarnings(ggplot2::ggplot_build(p))$plot$data$outcome)) > 1L &&
isTRUE(getOption("ggsurvfit.switch-color-linetype", default = FALSE))) {
lst_aes <- c(lst_aes, list(color = rlang::expr(.data$outcome)))
}
Expand Down
2 changes: 1 addition & 1 deletion R/add_confidence_interval.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ update_add_confidence_interval <- function(p, add_confidence_interval_empty_list
# prepare `aes()` call
.construct_ci_aes <- function(p, lst_aes = NULL, ribbon = FALSE) {
lst_aes <-
ggplot2::ggplot_build(p)$plot$layers[[1]]$computed_mapping[c("x", "color", "colour", "linetype")] %>%
suppressWarnings(ggplot2::ggplot_build(p))$plot$layers[[1]]$computed_mapping[c("x", "color", "colour", "linetype")] %>%
Filter(Negate(is.null), .) %>% # remove NULLs from list
utils::modifyList(val = lst_aes)

Expand Down
2 changes: 1 addition & 1 deletion R/add_legend_title.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ update_add_legend_title <- function(p, add_legend_title_empty_list) {
p$data$strata_label[1]

lst_labs <- list()
p_build <- ggplot2::ggplot_build(p)
p_build <- suppressWarnings(ggplot2::ggplot_build(p))

# if colour or fill present add the title for those aes()
if ("colour" %in% names(p_build$plot$labels)) {
Expand Down
2 changes: 1 addition & 1 deletion R/add_pvalue.R
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ update_add_pvalue <- function(p, add_pvalue_empty_list) {


# extract survfit object
build <- ggplot2::ggplot_build(p)
build <- suppressWarnings(ggplot2::ggplot_build(p))
survfit <- build$plot[["data"]][["survfit"]][[1]]

if (!inherits(survfit, c("survfit2", "tidycuminc"))) {
Expand Down
2 changes: 1 addition & 1 deletion R/add_quantile.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ update_add_quantile <- function(p, add_quantile_empty_list) {
"i" = "To plot multiple quantiles, call {.code add_quantile()} multiple times."
))

built_p <- ggplot2::ggplot_build(p)
built_p <- suppressWarnings(ggplot2::ggplot_build(p))
data <- built_p[["data"]][[1]]
data$monotonicity_type <- suppressWarnings(built_p$plot$data$monotonicity_type[1])
df_quantile_y <- .create_y_value_df(data, y_value)
Expand Down
2 changes: 1 addition & 1 deletion R/ggsurvfit.R
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ ggsurvfit <- function(x, type = "survival",
.is_ggsurvfit <- function(p, fun_name, required_cols = NULL) {
if (
!inherits(p, c("ggsurvfit", "ggcuminc")) ||
(!is.null(required_cols) && any(!required_cols %in% names(ggplot2::ggplot_build(p)$plot$data)))
(!is.null(required_cols) && any(!required_cols %in% names(suppressWarnings(ggplot2::ggplot_build(p))$plot$data)))
) {
cli::cli_abort(c(
"x" = "Cannot use {.code {fun_name}} in this context.",
Expand Down
10 changes: 7 additions & 3 deletions R/ggsurvfit_align_plots.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,14 @@
ggsurvfit_align_plots <- function(pltlist) {
# set all x axis ranges to be the same
x_range <-
ggplot2::ggplot_build(pltlist[[1]])$layout$panel_params[[1]]$x.range
suppressWarnings(
ggplot2::ggplot_build(pltlist[[1]])$layout$panel_params[[1]]$x.range
)
for (i in setdiff(seq_along(pltlist), 1L)) {
y_range <-
ggplot2::ggplot_build(pltlist[[i]])$layout$panel_params[[1]]$y.range
suppressWarnings(
ggplot2::ggplot_build(pltlist[[i]])$layout$panel_params[[1]]$y.range
)

pltlist[[i]] <-
pltlist[[i]] +
Expand All @@ -61,7 +65,7 @@ ggsurvfit_align_plots <- function(pltlist) {
}

# turn plots into grobs and determine number of columns
plots_grobs <- lapply(pltlist, ggplot2::ggplotGrob)
plots_grobs <- lapply(pltlist, function(x) suppressWarnings(ggplot2::ggplotGrob(x)))
ncols <- lapply(plots_grobs, function(x) dim(x)[[2]])
maxcols <- max(unlist(ncols))

Expand Down
2 changes: 1 addition & 1 deletion R/utils-add_risktable.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
}

# build the ggplot to inspect the internals ----------------------------------
plot_build <- ggplot2::ggplot_build(x)
plot_build <- suppressWarnings(ggplot2::ggplot_build(x))

# if plot is faceted, return plot without risktable --------------------------
if (.is_faceted(plot_build)) {
Expand Down
24 changes: 13 additions & 11 deletions tests/testthat/test-add_legend_title.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ test_that("add_legend_title() works", {
NA
)
expect_equal(
ggplot2::ggplot_build(sf1)$plot$labels$colour,
suppressWarnings(ggplot2::ggplot_build(sf1))$plot$labels$colour,
"Time from Surgery to Treatment"
)

Expand All @@ -23,11 +23,11 @@ test_that("add_legend_title() works", {
NA
)
expect_equal(
ggplot2::ggplot_build(sf2)$plot$labels$colour,
suppressWarnings(ggplot2::ggplot_build(sf2))$plot$labels$colour,
"Time from Surgery to Treatment"
)
expect_equal(
ggplot2::ggplot_build(sf2)$plot$labels$fill,
suppressWarnings(ggplot2::ggplot_build(sf2))$plot$labels$fill,
"Time from Surgery to Treatment"
)

Expand All @@ -42,15 +42,15 @@ test_that("add_legend_title() works", {
NA
)
expect_equal(
ggplot2::ggplot_build(sf3)$plot$labels$colour,
suppressWarnings(ggplot2::ggplot_build(sf3))$plot$labels$colour,
"Time from Surgery to Treatment"
)
expect_equal(
ggplot2::ggplot_build(sf3)$plot$labels$fill,
suppressWarnings(ggplot2::ggplot_build(sf3))$plot$labels$fill,
"Time from Surgery to Treatment"
)
expect_equal(
ggplot2::ggplot_build(sf3)$plot$labels$linetype,
suppressWarnings(ggplot2::ggplot_build(sf3))$plot$labels$linetype,
"Time from Surgery to Treatment"
)

Expand All @@ -65,15 +65,17 @@ test_that("add_legend_title() works", {
NA
)
expect_equal(
ggplot2::ggplot_build(cuminc1)$plot$labels$colour,
suppressWarnings(
ggplot2::ggplot_build(cuminc1)$plot$labels$colour
),
"Chemotherapy Treatment"
)
expect_equal(
ggplot2::ggplot_build(cuminc1)$plot$labels$fill,
suppressWarnings(ggplot2::ggplot_build(cuminc1))$plot$labels$fill,
"Chemotherapy Treatment"
)
expect_equal(
ggplot2::ggplot_build(cuminc1)$plot$labels$linetype,
suppressWarnings(ggplot2::ggplot_build(cuminc1))$plot$labels$linetype,
NULL
)

Expand All @@ -86,11 +88,11 @@ test_that("add_legend_title() works", {

# when no variable label present, the title is the variable name
expect_equal(
ggplot2::ggplot_build(
suppressWarnings(ggplot2::ggplot_build(
survfit2(Surv(mpg, am) ~ cyl, data = mtcars) %>%
ggsurvfit() +
add_legend_title()
)$plot$labels$colour,
))$plot$labels$colour,
"cyl"
)
})
52 changes: 27 additions & 25 deletions tests/testthat/test-add_risktable_strata_symbol.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ test_that("add_risktable_strata_symbol() works", {

test_that("add_risktable_strata_symbol() messaging works", {
expect_message(
print(survfit2(Surv(time, status) ~ sex, data = df_lung) %>%
ggsurvfit(linewidth = 1) +
add_confidence_interval() +
add_risktable_strata_symbol(risktable_group = "risktable_stats")),
suppressWarnings(
print(survfit2(Surv(time, status) ~ sex, data = df_lung) %>%
ggsurvfit(linewidth = 1) +
add_confidence_interval() +
add_risktable_strata_symbol(risktable_group = "risktable_stats"))
),
"must be run before"
)
expect_message(
Expand All @@ -65,7 +67,7 @@ test_that(".match_strata_level_to_color() works", {
expect_equal(
survfit2(Surv(time, status) ~ sex, data = df_lung) %>%
ggsurvfit() %>%
ggplot2::ggplot_build() %>%
{suppressWarnings(ggplot2::ggplot_build(.))} %>%
.match_strata_level_to_color(
risktable_group = "risktable_stats",
risktable_symbol_args = list(symbol = "\U25AC")
Expand All @@ -77,7 +79,7 @@ test_that(".match_strata_level_to_color() works", {
expect_equal(
survfit(Surv(time, status) ~ sex, data = df_lung) %>%
ggsurvfit() %>%
ggplot2::ggplot_build() %>%
{suppressWarnings(ggplot2::ggplot_build(.))} %>%
.match_strata_level_to_color(
risktable_group = "risktable_stats",
risktable_symbol_args = list(symbol = "\U25AC")
Expand All @@ -89,7 +91,7 @@ test_that(".match_strata_level_to_color() works", {
expect_equal(
survfit2(Surv(time, status) ~ as.numeric(sex), data = df_lung) %>%
ggsurvfit() %>%
ggplot2::ggplot_build() %>%
{suppressWarnings(ggplot2::ggplot_build(.))} %>%
.match_strata_level_to_color(
risktable_group = "risktable_stats",
risktable_symbol_args = list(symbol = "\U25AC")
Expand All @@ -101,7 +103,7 @@ test_that(".match_strata_level_to_color() works", {
expect_equal(
survfit(Surv(time, status) ~ as.numeric(sex), data = df_lung) %>%
ggsurvfit() %>%
ggplot2::ggplot_build() %>%
{suppressWarnings(ggplot2::ggplot_build(.))} %>%
.match_strata_level_to_color(
risktable_group = "risktable_stats",
risktable_symbol_args = list(symbol = "\U25AC")
Expand All @@ -113,7 +115,7 @@ test_that(".match_strata_level_to_color() works", {
expect_equal(
survfit2(Surv(time, status) ~ as.character(sex), data = df_lung) %>%
ggsurvfit() %>%
ggplot2::ggplot_build() %>%
{suppressWarnings(ggplot2::ggplot_build(.))} %>%
.match_strata_level_to_color(
risktable_group = "risktable_stats",
risktable_symbol_args = list(symbol = "\U25AC")
Expand All @@ -125,7 +127,7 @@ test_that(".match_strata_level_to_color() works", {
expect_equal(
survfit(Surv(time, status) ~ as.character(sex), data = df_lung) %>%
ggsurvfit() %>%
ggplot2::ggplot_build() %>%
{suppressWarnings(ggplot2::ggplot_build(.))} %>%
.match_strata_level_to_color(
risktable_group = "risktable_stats",
risktable_symbol_args = list(symbol = "\U25AC")
Expand All @@ -138,7 +140,7 @@ test_that(".match_strata_level_to_color() works", {
survfit2(Surv(time, status) ~ sex,
data = df_lung %>% dplyr::mutate(sex = glue::glue("{as.character(sex)}"))) %>%
ggsurvfit() %>%
ggplot2::ggplot_build() %>%
{suppressWarnings(ggplot2::ggplot_build(.))} %>%
.match_strata_level_to_color(
risktable_group = "risktable_stats",
risktable_symbol_args = list(symbol = "\U25AC")
Expand All @@ -151,7 +153,7 @@ test_that(".match_strata_level_to_color() works", {
survfit(Surv(time, status) ~ sex,
data = df_lung %>% dplyr::mutate(sex = glue::glue("{as.character(sex)}"))) %>%
ggsurvfit() %>%
ggplot2::ggplot_build() %>%
{suppressWarnings(ggplot2::ggplot_build(.))} %>%
.match_strata_level_to_color(
risktable_group = "risktable_stats",
risktable_symbol_args = list(symbol = "\U25AC")
Expand All @@ -163,7 +165,7 @@ test_that(".match_strata_level_to_color() works", {
expect_equal(
survfit2(Surv(time, status) ~ factor(sex, ordered = TRUE), data = df_lung) %>%
ggsurvfit() %>%
ggplot2::ggplot_build() %>%
{suppressWarnings(ggplot2::ggplot_build(.))} %>%
.match_strata_level_to_color(
risktable_group = "risktable_stats",
risktable_symbol_args = list(symbol = "\U25AC")
Expand All @@ -175,7 +177,7 @@ test_that(".match_strata_level_to_color() works", {
expect_equal(
survfit(Surv(time, status) ~ factor(sex, ordered = TRUE), data = df_lung) %>%
ggsurvfit() %>%
ggplot2::ggplot_build() %>%
{suppressWarnings(ggplot2::ggplot_build(.))} %>%
.match_strata_level_to_color(
risktable_group = "risktable_stats",
risktable_symbol_args = list(symbol = "\U25AC")
Expand All @@ -188,7 +190,7 @@ test_that(".match_strata_level_to_color() works", {
survfit2(Surv(time, status) ~ sex,
data = df_lung %>% dplyr::mutate(sex = factor(sex, levels = c("Female", "Male")))) %>%
ggsurvfit() %>%
ggplot2::ggplot_build() %>%
{suppressWarnings(ggplot2::ggplot_build(.))} %>%
.match_strata_level_to_color(
risktable_group = "risktable_stats",
risktable_symbol_args = list(symbol = "\U25AC")
Expand All @@ -201,7 +203,7 @@ test_that(".match_strata_level_to_color() works", {
survfit(Surv(time, status) ~ sex,
data = df_lung %>% dplyr::mutate(sex = factor(sex, levels = c("Female", "Male")))) %>%
ggsurvfit() %>%
ggplot2::ggplot_build() %>%
{suppressWarnings(ggplot2::ggplot_build(.))} %>%
.match_strata_level_to_color(
risktable_group = "risktable_stats",
risktable_symbol_args = list(symbol = "\U25AC")
Expand All @@ -214,7 +216,7 @@ test_that(".match_strata_level_to_color() works", {
survfit2(Surv(time, status) ~ sex,
data = df_lung %>% dplyr::mutate(sex = factor(sex, levels = c("Male", "Female")))) %>%
ggsurvfit() %>%
ggplot2::ggplot_build() %>%
{suppressWarnings(ggplot2::ggplot_build(.))} %>%
.match_strata_level_to_color(
risktable_group = "risktable_stats",
risktable_symbol_args = list(symbol = "\U25AC")
Expand All @@ -227,7 +229,7 @@ test_that(".match_strata_level_to_color() works", {
survfit(Surv(time, status) ~ sex,
data = df_lung %>% dplyr::mutate(sex = factor(sex, levels = c("Male", "Female")))) %>%
ggsurvfit() %>%
ggplot2::ggplot_build() %>%
{suppressWarnings(ggplot2::ggplot_build(.))} %>%
.match_strata_level_to_color(
risktable_group = "risktable_stats",
risktable_symbol_args = list(symbol = "\U25AC")
Expand All @@ -239,7 +241,7 @@ test_that(".match_strata_level_to_color() works", {
expect_equal(
survfit2(Surv(time, status) ~ ph.ecog, data = df_lung) %>%
ggsurvfit() %>%
ggplot2::ggplot_build() %>%
{suppressWarnings(ggplot2::ggplot_build(.))} %>%
.match_strata_level_to_color(
risktable_group = "risktable_stats",
risktable_symbol_args = list(symbol = "\U25AC")
Expand All @@ -253,7 +255,7 @@ test_that(".match_strata_level_to_color() works", {
expect_equal(
survfit(Surv(time, status) ~ ph.ecog, data = df_lung) %>%
ggsurvfit() %>%
ggplot2::ggplot_build() %>%
{suppressWarnings(ggplot2::ggplot_build(.))} %>%
.match_strata_level_to_color(
risktable_group = "risktable_stats",
risktable_symbol_args = list(symbol = "\U25AC")
Expand All @@ -267,7 +269,7 @@ test_that(".match_strata_level_to_color() works", {
expect_equal(
survfit2(Surv(time, status) ~ 1, data = df_lung) %>%
ggsurvfit() %>%
ggplot2::ggplot_build() %>%
{suppressWarnings(ggplot2::ggplot_build(.))} %>%
.match_strata_level_to_color(
risktable_group = "risktable_stats",
risktable_symbol_args = list(symbol = "\U25AC")
Expand All @@ -278,7 +280,7 @@ test_that(".match_strata_level_to_color() works", {
expect_equal(
survfit(Surv(time, status) ~ 1, data = df_lung) %>%
ggsurvfit() %>%
ggplot2::ggplot_build() %>%
{suppressWarnings(ggplot2::ggplot_build(.))} %>%
.match_strata_level_to_color(
risktable_group = "risktable_stats",
risktable_symbol_args = list(symbol = "\U25AC")
Expand All @@ -289,8 +291,8 @@ test_that(".match_strata_level_to_color() works", {
expect_equal(
survfit2(Surv(time, status) ~ 1, data = df_lung) %>%
ggsurvfit(color = "#00BFC4") %>%
ggplot2::ggplot_build() %>%
.match_strata_level_to_color(
{suppressWarnings(ggplot2::ggplot_build(.))} %>%
.match_strata_level_to_color(
risktable_group = "risktable_stats",
risktable_symbol_args = list(symbol = "\U25AC")
),
Expand All @@ -300,7 +302,7 @@ test_that(".match_strata_level_to_color() works", {
expect_equal(
survfit(Surv(time, status) ~ 1, data = df_lung) %>%
ggsurvfit(color = "#00BFC4") %>%
ggplot2::ggplot_build() %>%
{suppressWarnings(ggplot2::ggplot_build(.))} %>%
.match_strata_level_to_color(
risktable_group = "risktable_stats",
risktable_symbol_args = list(symbol = "\U25AC")
Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test-ggsurvfit.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ test_that("ggsurvfit() works", {
# test the default ADTTE x-axis label comes from PARAM column
expect_equal(
ggsurvfit(survfit2(Surv_CNSR() ~ 1, data = adtte)) %>%
ggplot2::ggplot_build() %>%
{suppressWarnings(ggplot2::ggplot_build(.))} %>%
`[[`("plot") %>%
`[[`("labels") %>%
`[[`("x"),
Expand Down Expand Up @@ -117,7 +117,7 @@ test_that("ggsurvfit() works", {
expect_equal(
suppressWarnings(survfit2(Surv_CNSR() ~ 1, data = df_param2)) %>%
ggsurvfit() %>%
ggplot2::ggplot_build() %>%
{suppressWarnings(ggplot2::ggplot_build(.))} %>%
`[[`("plot") %>%
`[[`("labels") %>%
`[[`("x"),
Expand All @@ -128,7 +128,7 @@ test_that("ggsurvfit() works", {
expect_equal(
survfit2(Surv_CNSR() ~ PARAM, data = df_param2) %>%
ggsurvfit() %>%
ggplot2::ggplot_build() %>%
{suppressWarnings(ggplot2::ggplot_build(.))} %>%
`[[`("plot") %>%
`[[`("labels") %>%
`[[`("x"),
Expand Down
Loading
Loading