Skip to content

Commit

Permalink
addresses kassambara#578 - use dplyr::select insstead of select_
Browse files Browse the repository at this point in the history
  • Loading branch information
tbaer-c7ks7s committed Apr 1, 2022
1 parent 54f0564 commit c4a3de1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
7 changes: 3 additions & 4 deletions R/ggsurvplot_combine.R
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ ggsurvplot_combine <- function(fit, data,
all.levels <- c(all.levels, .levels(ss$strata))
# convert strata into character before binding
# avoid this warning: Unequal factor levels: coercing to character
grouped.d$survsummary <- map(grouped.d$survsummary,
grouped.d$survsummary <- purrr::map(grouped.d$survsummary,
function(x){
x$strata <- as.character(x$strata)
x
Expand Down Expand Up @@ -161,9 +161,8 @@ ggsurvplot_combine <- function(fit, data,
survtable$strata <- paste(fitname, "::", survtable$strata, sep = "") %>%
factor(levels = strata.levels)
survtable %>%
dplyr::select_( .dots = c("strata", "time", "n.risk", "pct.risk",
"n.event", "cum.n.event", "n.censor",
"cum.n.censor", "strata_size"))
dplyr::select(strata, time, n.risk, pct.risk, n.event, cum.n.event,
n.censor, cum.n.censor, strata_size)))
}

grouped.d <- grouped.d %>%
Expand Down
18 changes: 18 additions & 0 deletions tests/testthat/test-ggsurvplot_combine.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
context("test-ggsurvplot_combine")

library(dplyr)
library(survival)
data("lung")
start_time <- 250
fit1 <- survfit(Surv(time, status) ~ sex, data = lung)
fit2 <- survfit(Surv(time, status) ~ sex, data = lung, start.time=start_time)

test_that("survplot_combine plots successfully into 4 lines; second 2 fits have only (0,1) before start_time", {
p <- ggsurvplot_combine(list(
original=fit1, conditional=fit2
), data = lung)
.build <- ggplot_build(p$plot)
.build_data <- .build$data[[1]]
expect_equal(length(unique(.build_data[['group']])), 4)
expect_lt(nrow(.build_data[(.build_data[['group']] >= 3) & (.build_data[['x']] < start_time), ]), 3)
})

0 comments on commit c4a3de1

Please sign in to comment.