@@ -42,21 +42,19 @@ formula.surv_reg <- function(x, recipe, ...) {
42
42
43
43
# engine-speciifc options (e.g. spark needing censor var in text)
44
44
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 )
53
47
if (any(rec_vars $ role == " strata" ))
54
48
warning(
55
49
" `flexsurv` does not use the `strata` function; instead use " ,
56
50
" the parameter roles for differential values (e.g. `sigma`)." ,
57
51
call. = FALSE
58
52
)
59
53
}
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
+ }
60
58
61
59
form <- try(as.formula(form_text ), silent = TRUE )
62
60
if (inherits(form , " try-error" ))
@@ -65,3 +63,19 @@ formula.surv_reg <- function(x, recipe, ...) {
65
63
}
66
64
67
65
flexsurv_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