Skip to content

Commit

Permalink
Stop deletion of snapshot files (#366)
Browse files Browse the repository at this point in the history
  • Loading branch information
gowerc authored Jun 21, 2024
1 parent e6fd6ff commit 36864eb
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 36 deletions.
2 changes: 1 addition & 1 deletion R/brier_score.R
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ reverse_km_cen_first <- function(t, times, events) {
survival::Surv(times, cen_events) ~ 1,
data = dat
)
preds <- summary(mod, times = t, extend = TRUE)$surv
preds <- summary(mod, times = t[order(t)], extend = TRUE)$surv

assert_that(
length(preds) == length(t)
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
78 changes: 46 additions & 32 deletions tests/testthat/test-survival_plot.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@

## Code to re-run this from commandline
# JMPOST_GRAPH_SNAPSHOT=TRUE \
# NOT_CRAN=TRUE \
# Rscript -e "devtools::load_all(); testthat::test_file('tests/testthat/test-survival_plot.R')"

snap_dir <- file.path(testthat::test_path(), "_snaps", "survival_plot")

test_that("survival_plot works as expected", {

Expand Down Expand Up @@ -55,54 +61,62 @@ test_that("survival_plot works as expected", {
get_data(3, "C")
)

p1 <- survival_plot(
res,
add_ci = TRUE,
add_wrap = TRUE,
kmdf = NULL,
y_label = expression(frac(1, 2) + S(t^2)),
x_label = expression(thd[3])
)
testthat::expect_no_error({
p1 <- survival_plot(
res,
add_ci = TRUE,
add_wrap = TRUE,
kmdf = NULL,
y_label = expression(frac(1, 2) + S(t^2)),
x_label = expression(thd[3])
)
})


announce_snapshot_file(file.path(snap_dir, "wrap-ci.svg"))
if (is_graph_snapshot_enabled()) {
vdiffr::expect_doppelganger(
"survival_plot with wrap and ci",
"wrap-ci",
p1
)
}

testthat::expect_no_error({
p2 <- survival_plot(
res,
add_ci = FALSE,
add_wrap = FALSE,
kmdf = NULL,
y_label = expression(frac(1, 2) + S(t^2)),
x_label = expression(thd[3])
)
})

p2 <- survival_plot(
res,
add_ci = FALSE,
add_wrap = FALSE,
kmdf = NULL,
y_label = expression(frac(1, 2) + S(t^2)),
x_label = expression(thd[3])
)

announce_snapshot_file(file.path(snap_dir, "nowrap-noci.svg"))
if (is_graph_snapshot_enabled()) {
vdiffr::expect_doppelganger(
"survival_plot with no wrap and no ci",
"nowrap-noci",
p2
)
}


p3 <- survival_plot(
res,
add_ci = FALSE,
add_wrap = FALSE,
kmdf = dat,
y_label = expression(frac(1, 2) + S(t^2)),
x_label = expression(thd[3])
) +
theme(legend.position = "bottom") +
scale_y_continuous(trans = "sqrt")

testthat::expect_no_error({
p3 <- survival_plot(
res,
add_ci = FALSE,
add_wrap = FALSE,
kmdf = dat,
y_label = expression(frac(1, 2) + S(t^2)),
x_label = expression(thd[3])
) +
theme(legend.position = "bottom") +
scale_y_continuous(trans = "sqrt")
})

announce_snapshot_file(file.path(snap_dir, "nowrap-noci-km-ggplot2.svg"))
if (is_graph_snapshot_enabled()) {
vdiffr::expect_doppelganger(
"survival_plot-no wrap + no ci + km + ggplot2 ",
"nowrap-noci-km-ggplot2",
p3
)
}
Expand Down

0 comments on commit 36864eb

Please sign in to comment.