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

addresses #578 - use dplyr::select insstead of select_ #579

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ Suggests:
testthat,
rmarkdown
VignetteBuilder: knitr
URL: https://rpkgs.datanovia.com/survminer/index.html
URL: https://rpkgs.datanovia.com/survminer/index.html
BugReports: https://github.com/kassambara/survminer/issues
RoxygenNote: 7.1.1
RoxygenNote: 7.2.3
Collate:
'BMT.R'
'BRCAOV.survInfo.R'
Expand Down
6 changes: 3 additions & 3 deletions R/ggcoxdiagnostics.R
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ ggcoxdiagnostics <- function (fit,
else col_names <- names(stats::coef(fit))
colnames(res) <- col_names
res$xval <- xval
data2plot <- tidyr::gather_(res,
key_col = "covariate", value_col = "res",
gather_col = col_names)
data2plot <- tidyr::gather(res,
key = "covariate", value = "res",
col_names)

gplot <- ggplot(aes(xval, res), data = data2plot) +
geom_point(col = point.col, shape = point.shape,
Expand Down
12 changes: 6 additions & 6 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,9 @@ 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( dplyr::all_of(c("strata", "time", "n.risk", "pct.risk",
"n.event", "cum.n.event", "n.censor",
"cum.n.censor", "strata_size")))
}

grouped.d <- grouped.d %>%
Expand Down Expand Up @@ -199,8 +199,8 @@ ggsurvplot_combine <- function(fit, data,
#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

if(keep.data){
res$data.survplot <- tibble::as.tibble(all.survsummary)
res$data.survtable <- tibble::as.tibble(all.survtable)
res$data.survplot <- tibble::as_tibble(all.survsummary)
res$data.survtable <- tibble::as_tibble(all.survtable)
}


Expand Down
4 changes: 2 additions & 2 deletions R/ggsurvplot_facet.R
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,10 @@ ggsurvplot_facet <- function(fit, data, facet.by,
pvalue <- surv_pvalue(grouped.d$fit, grouped.d$data, pval.coord = pval.coord,
pval.method.coord = pval.method.coord,...) %>%
dplyr::bind_rows() %>%
tibble::as.tibble()
tibble::as_tibble()
# Select the grouping variable columns and cbind the corresponding pvalue
pvals.df <- grouped.d %>%
dplyr::select_( .dots = facet.by) %>%
dplyr::select(!!!syms(facet.by)) %>%
dplyr::bind_cols(pvalue)
pval.x <- pval.y <- pval.txt <- method.x <- method.y <- method <- NULL
p <- p +
Expand Down
2 changes: 1 addition & 1 deletion R/surv_median.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ surv_median <- function(fit, combine = FALSE){
.table$strata <- rownames(.table)

.table <- .table %>%
dplyr::select_(.dots = c("strata", "median", "`0.95LCL`", "`0.95UCL`"))
dplyr::select(dplyr::all_of(c("strata", "median", "0.95LCL", "0.95UCL")))
colnames(.table) <- c("strata", "median", "lower", "upper")
rownames(.table) <- NULL
.table
Expand Down
4 changes: 2 additions & 2 deletions man/ggcoxdiagnostics.Rd

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

4 changes: 2 additions & 2 deletions man/ggcoxfunctional.Rd

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

4 changes: 2 additions & 2 deletions man/ggcoxzph.Rd

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

10 changes: 2 additions & 8 deletions man/ggsurvplot_df.Rd

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

16 changes: 5 additions & 11 deletions man/ggsurvtable.Rd

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

6 changes: 3 additions & 3 deletions man/ggsurvtheme.Rd

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

2 changes: 2 additions & 0 deletions tests/testthat/setup-load_data.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
library(survival)
data('cancer')
16 changes: 16 additions & 0 deletions tests/testthat/test-ggcoxdiagnostics.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
test_that('ggcoxdiagnostics creates plot with all the observations', {
cph <- coxph(Surv(futime, fustat) ~ rx + age, data=ovarian)
p <- ggcoxdiagnostics(cph, type="deviance")
.build <- ggplot_build(p)
expect_equal(nrow(.build$data[[1]]), nrow(ovarian))
})

test_that('ggcoxdiagnostics with second type two rows for each observed event*term', {
cph <- coxph(Surv(futime, fustat) ~ rx + age, data=ovarian)
qty_terms <- length(attr(terms(cph$formula), "term.labels"))
qty_events <- sum(ovarian$fustat==1)
p <- ggcoxdiagnostics(cph, type="schoenfeld")
.build <- ggplot_build(p)
expect_equal(nrow(.build$data[[1]]), qty_terms*qty_events)
})

21 changes: 21 additions & 0 deletions tests/testthat/test-ggsurvplot_combine.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
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)
})

test_that("survplot_combine includes dataframes when keep.data==TRUE", {
p <- ggsurvplot_combine(list(
original=fit1, conditional=fit2
), data = lung, keep.data = TRUE)
expect_equal(length(names(p)), 3)
})
21 changes: 21 additions & 0 deletions tests/testthat/test-ggsurvplot_facet.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
test_that("ggsurvplot_facet creates the correct quanitty of subplots", {
fit <- survfit(Surv(time, status) ~ sex, data=kidney)
p <- ggsurvplot_facet(fit, kidney, facet.by='disease')
.build <- ggplot_build(p)
expect_equal(nrow(.build$data[[2]]),
length(unique(kidney[['disease']])))

fit <- survfit(Surv(time, status) ~ disease, data=kidney)
p <- ggsurvplot_facet(fit, kidney, facet.by='sex')
.build <- ggplot_build(p)
expect_equal(nrow(.build$data[[2]]),
length(unique(kidney[['sex']])))
})

test_that("ggsurvplot_facet calculates pvalue for each facet", {
fit <- survfit(Surv(time, status) ~ sex, data=kidney)
p <- ggsurvplot_facet(fit, kidney, facet.by='disease', pval = TRUE)
.build <- ggplot_build(p)
expect_equal(nrow(.build$plot$layer[[4]][['data']]),
length(unique(kidney[['disease']])))
})
9 changes: 5 additions & 4 deletions tests/testthat/test-ggsurvtable.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
context("test-ggsurvtable")

library(dplyr)
library("survival")
data("lung")
fit <- survfit(Surv(time, status) ~ sex, data = lung)


test_that("survtable y axis label colors work", {
library(dplyr)
library("survival")
#data("lung", package = "survival")
fit <- survfit(Surv(time, status) ~ sex, data = lung)
p <- ggrisktable(fit, data = lung, color = "strata")
.build <- ggplot_build(p)
.build_data <- .build$data[[1]]
Expand Down
6 changes: 6 additions & 0 deletions tests/testthat/test-surv_median.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
test_that("surv_median calculates medians", {
df_medians <- surv_median(survfit(Surv(time, status) ~ sex,
data=lung))
expect_equal(df_medians[['median']], c(270,426))
expect_lt(df_medians[['lower']][2], 426)
})