pharmaverse / ggsurvfit

http://www.danieldsjoberg.com/ggsurvfit/
Other
67 stars 19 forks source link

Feature request: Non-syntactic names in `survfit2` objects #162

Closed mattsecrest closed 8 months ago

mattsecrest commented 10 months ago

I always wished survfit objects accepted non-syntactic names. Maybe something worth adding to survfit2?

library(ggsurvfit)
library(tibble)

df <- tibble(
  os_months = abs(rnorm(100, 12, .5)),
  os_event = rbinom(100, 1, .5),
  group = sample(c("group 1", "group 2"), 100, replace = TRUE),
  `group non-syntactic` = group
)

# This works
survfit2(
  Surv(os_months, os_event) ~ group,
  data = df
)

# This does not work
survfit2(
  Surv(os_months, os_event) ~ `group non-syntactic`,
  data = df
)

Even fixing the error message could be nice, as it is quite cryptic:

Error in `[.data.frame`(mf, ll) : undefined columns selected

ddsjoberg commented 10 months ago

Hmmmm, we could say that survfit2() does accept these kinds of names. But the error you're seeing is what happens when we pass those args to survival::survfit() 😉

Are you thinking we could parse the formula looking for these names before passing to survival::survfit() and give a warning before the error message appears?

mattsecrest commented 10 months ago

I see. Since this is ultimately thrown by survival, let's see if we can fix it there instead: https://github.com/therneau/survival/issues/232

ddsjoberg commented 8 months ago

Hey hey @mattsecrest ! I am going to go ahead and close this since it'll automatically work when survival is updated