Skip to content

Commit a68cf23

Browse files
committed
function to translate std R surv formula to spark
1 parent 5748794 commit a68cf23

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

R/misc.R

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,20 @@ resolve_args <- function(args, ...) {
101101
}
102102
args
103103
}
104+
105+
106+
# A function to convert a R formula to spark format
107+
surv_to_spark_formula <- function(f) {
108+
if (!inherits(f, "formula"))
109+
stop("A formula is required.")
110+
if (length(f[[2]]) != 3)
111+
stop("spark requires the `Surv` object to have a ",
112+
"censoring indicator.")
113+
if (!all.equal(f[[2]][[1]], as.name("Surv")))
114+
stop("The formula sould contain a `Surv` object.")
115+
f2 <- f
116+
f2[[2]] <- f[[2]][[2]]
117+
list(formula = f2, censor = deparse(f[[2]][[3]]))
118+
}
119+
120+

0 commit comments

Comments
 (0)