tidymodels / tidymodels/workflows

workflows confuses an `id` special for `dplyr::id()`

Open
#268 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
R
Stars
211
Forks
26
Avg merge
1h 58m
Merged PRs (30d)
1

Description

See https://stackoverflow.com/questions/79163528/multistate-survival-models-with-censored-and-tidymodels

This might end up being a parsnip issue but we should start here.

library(tidyverse)
library(tidymodels)
library(censored)
#> Loading required package: survival

df <- tibble(
  sample_id = seq(1:1000),
  sex = sample(c("Male","Female"), 1000, replace = T),
  duration = rnorm(1000, mean = 75, sd = 7),
  outcome = sample(c("censor","Lost","Won"), 1000, replace = T)
  
) %>%
  mutate(
    outcome = factor(outcome)
  )

mod_df <- df %>%
  mutate(
    sale_surv = Surv(duration, outcome),
    .keep = "unused"
  )

set.seed(1988)

mod_split <- initial_split(mod_df)
mod_train <- training(mod_split)
mod_test <- testing(mod_split)

mod_rec <- recipe(sale_surv ~ sex, data = mod_train) # no `id` here 

mod_spec <- proportional_hazards() %>%
  set_mode("censored regression") %>%
  set_engine("survival") 

mod_wflow <- workflow() %>%
  add_recipe(mod_rec) %>%
  add_model(mod_spec, formula = sale_surv ~ sex + id(sample_id)) # add a formula here

mod_fit <- fit(mod_wflow, data = mod_train)
#> Error:
#> ! `id()` was deprecated in dplyr 0.5.0 and is now defunct.
#> ℹ Please use `vctrs::vec_group_id()` instead.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the reproducible workflow example in the issue and inspect the workflow/model-formula entry points that process id(sample_id). Determine where the formula is evaluated and add regression coverage showing that a column named id is not confused with dplyr::id(); done means the example fits successfully without the deprecation error.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.