tests/testthat/test-scale_ggsurvfit.R

test_that("scale_ggsurvfit() works", {
  expect_equal(
    (survfit2(Surv(time, status) ~ sex, df_lung) %>%
       ggsurvfit() +
       scale_ggsurvfit()) %>%
      {ggplot2::ggplot_build(.)$layout$panel_params[[1]]$x.range},
    (survfit2(Surv(time, status) ~ sex, df_lung) %>%
       ggsurvfit() +
       scale_x_continuous(expand = c(0.025, 0)) +
       scale_y_continuous(
         limits = c(0 - sqrt(.Machine$double.eps), 1 + sqrt(.Machine$double.eps)),
         expand = c(0.025, 0)
       )) %>%
      {ggplot2::ggplot_build(.)$layout$panel_params[[1]]$x.range}
  )

  expect_equal(
    (survfit2(Surv(time, status) ~ sex, df_lung) %>%
       ggsurvfit() +
       scale_ggsurvfit()) %>%
      {ggplot2::ggplot_build(.)$layout$panel_params[[1]]$y.range},
    (survfit2(Surv(time, status) ~ sex, df_lung) %>%
       ggsurvfit() +
       scale_x_continuous(expand = c(0.015, 0)) +
       scale_y_continuous(
         expand = c(0.025, 0),
         limits = c(0 - sqrt(.Machine$double.eps), 1 + sqrt(.Machine$double.eps)),
         label = scales::label_percent()
       )) %>%
      {ggplot2::ggplot_build(.)$layout$panel_params[[1]]$y.range}
  )
})

test_that("label_percent_imposter() works", {
  probs <- 0:4 * 0.25
  expect_equal(
    label_percent_imposter(probs),
    scales::label_percent()(probs)
  )
})

Try the ggsurvfit package in your browser

Any scripts or data that you put into this service are public.

ggsurvfit documentation built on Nov. 2, 2023, 5:33 p.m.