2626# ' @param y (`Surv` or `string`)\cr
2727# ' an object of class `Surv` created using [survival::Surv()]. This object will be passed as the left-hand side of
2828# ' the formula constructed and passed to [survival::survfit()]. This object can also be passed as a string.
29- # ' @param variables (`character` )\cr
29+ # ' @param variables ([`tidy-select`][dplyr::dplyr_tidy_select] )\cr
3030# ' stratification variables to be passed as the right-hand side of the formula constructed and passed to
31- # ' [survival::survfit()].
31+ # ' [survival::survfit()]. Use `variables=NULL` for an unstratified model, e.g. `Surv() ~ 1`.
3232# ' @param method.args (named `list`)\cr
3333# ' named list of arguments that will be passed to [survival::survfit()].
3434# ' @inheritParams rlang::args_dots_empty
@@ -172,7 +172,7 @@ ard_survival_survfit.data.frame <- function(x, y, variables,
172172 # check/process inputs -------------------------------------------------------
173173 check_not_missing(y )
174174 check_not_missing(variables )
175- check_class( variables , " character " )
175+ cards :: process_selectors( x , variables = {{ variables }} )
176176
177177 # process outcome as string --------------------------------------------------
178178 y <- enquo(y )
@@ -182,9 +182,15 @@ ard_survival_survfit.data.frame <- function(x, y, variables,
182182 else y <- expr_deparse(quo_get_expr(y )) # styler: off
183183
184184 # build model ----------------------------------------------------------------
185+ survfit_formula <-
186+ case_switch(
187+ ! is_empty(variables ) ~ stats :: reformulate(termlabels = bt(variables ), response = y ),
188+ .default = stats :: reformulate(termlabels = " 1" , response = y )
189+ )
190+
185191 construct_model(
186192 data = x ,
187- formula = stats :: reformulate( termlabels = bt( variables ), response = y ) ,
193+ formula = survfit_formula ,
188194 method = " survfit" ,
189195 package = " survival" ,
190196 method.args = {{ method.args }}
0 commit comments