@@ -42,21 +42,19 @@ formula.surv_reg <- function(x, recipe, ...) {
4242
4343 # engine-speciifc options (e.g. spark needing censor var in text)
4444 if (! is.null(x $ engine ) && x $ engine == " flexsurv" ) {
45- extra_ind <- which(rec_vars $ role %in% flexsurv_params )
46- if (length(extra_ind ) > 0 ) {
47- extra_terms <- paste0(
48- rec_vars $ role [extra_ind ], " (" ,
49- rec_vars $ variable [extra_ind ], " )"
50- )
51- form_text <- paste0(form_text , " +" , paste0(extra_terms , collapse = " +" ))
52- }
45+ spec_text <- specials(rec_vars , flexsurv_params )
46+ form_text <- paste0(form_text , spec_text )
5347 if (any(rec_vars $ role == " strata" ))
5448 warning(
5549 " `flexsurv` does not use the `strata` function; instead use " ,
5650 " the parameter roles for differential values (e.g. `sigma`)." ,
5751 call. = FALSE
5852 )
5953 }
54+ if (! is.null(x $ engine ) && x $ engine == " survival" ) {
55+ spec_text <- specials(rec_vars , survival_params )
56+ form_text <- paste0(form_text , spec_text )
57+ }
6058
6159 form <- try(as.formula(form_text ), silent = TRUE )
6260 if (inherits(form , " try-error" ))
@@ -65,3 +63,19 @@ formula.surv_reg <- function(x, recipe, ...) {
6563}
6664
6765flexsurv_params <- c(" sigma" , " shape" , " sdlog" , " Q" , " k" , " P" , " S1" , " s2" )
66+ survival_params <- c(" strata" , " cluster" )
67+
68+ # This will add terms to the formulas based on _specials_ such as survival stratas etc
69+ specials <- function (info , specials ) {
70+ extra_ind <- which(info $ role %in% specials )
71+ if (length(extra_ind ) > 0 ) {
72+ extra_terms <- paste0(
73+ info $ role [extra_ind ], " (" ,
74+ info $ variable [extra_ind ], " )"
75+ )
76+ form_text <- paste0(" +" , paste0(extra_terms , collapse = " +" ))
77+ } else form_text <- " "
78+ form_text
79+ }
80+
81+
0 commit comments