Modeling package with `Surv()` Outcome: How to incorporate with recipes and tidymodels


I am using the hardhat package to write a package that performs modeling for time to event outcomes. We use survival::Surv() to construct the outcome. The hardhat documentation was great for helping get a "formula" method working, e.g. foo(Surv(time, status) ~ var1 + var2).

The hardhat documentation also walks through how to include a recipes method, so users can construct the models this way. But I am getting an error. What is the best way to integrate a modeling package with time to event outcomes into a tidymodels framework?

Thank you!


recipes::recipe(Surv(time, status) ~ age, data = lung)
#> Error: No in-line functions should be used here; use steps to define baking actions.

Created on 2021-11-04 by the reprex package (v2.0.1)


Check out the new censored package from the tidymodels crew.
Parsnip Wrappers for Survival Models • censored (

It should cover most of your needs.

Thanks for the reply @duringju211 !

I watched Max Kuhn's presentation on the package yesterday at the R in Pharma Conference. The examples he went through, and those on the website, don't use recipes to construct the models. Rather they use classes of models with supported engines to build those models. Is that the recommended approach? I haven't seen any tutorials on writing an engine in this manner...


proportional_hazards() %>%
  set_engine("survival") %>%
  fit(Surv(time, status) ~ age + ph.ecog, data = lung) %>%
#> [1] "_coxph"    "model_fit"

Created on 2021-11-04 by the reprex package (v2.0.1)