tbl_survfit_errors: Common Sources of Error with 'tbl_survfit()'

tbl_survfit_errorsR Documentation

Common Sources of Error with tbl_survfit()

Description

When functions add_n() and add_p() are run after tbl_survfit(), the original call to survival::survfit() is extracted and the ⁠formula=⁠ and ⁠data=⁠ arguments are used to calculate the N or p-value.

When the values of the ⁠formula=⁠ and ⁠data=⁠ are unavailable, the functions cannot execute. Below are some tips to modify your code to ensure all functions run without issue.

  1. Let tbl_survfit() construct the survival::survfit() for you by passing a data frame to tbl_survfit(). The survfit model will be constructed in a manner ensuring the formula and data are available. This only works if you have a stratified model.

    Instead of the following line

    survfit(Surv(ttdeath, death) ~ trt, trial) %>%
      tbl_survfit(times = c(12, 24))
    

    Use this code

    trial %>%
      select(ttdeath, death, trt) %>%
      tbl_survfit(y = Surv(ttdeath, death), times = c(12, 24))
    
  2. Construct an expression of the survival::survfit() before evaluating it. Ensure the formula and data are available in the call by using the tidyverse bang-bang operator, ⁠!!⁠.

    Use this code

    formula_arg <- Surv(ttdeath, death) ~ 1
    data_arg <- trial
    rlang::expr(survfit(!!formula_arg, !!data_arg)) %>%
      eval() %>%
      tbl_survfit(times = c(12, 24))
    

ddsjoberg/gtsummary documentation built on Nov. 3, 2023, 11:42 a.m.