0

I'm creating a function which takes column names as arguments and to plot survival plots. however my arguments can't be found in the calling function.

thanks in advance for your help

plt_survive <- function(data_in, time_var, event_var, group_var){

require(ggsurvfit)
require(survival)

  p_tittle <- as_label(group_var) # use plot title
  p <- survfit2(Surv({{time_var}}, {{event_var}}) ~ {{group_var}}, data = data_in) %>%
  ggsurvfit(linewidth = 1) +
  add_confidence_interval() +
  add_risktable()
  return(p)
}

plt_survive(data_in=df_test, time_var=time_to_event_yearmonth, event_var=dfs_event, group_var=restaging)

##### Error in is_quosure(quo) : object 'restaging' not found

data looks like this

df_test <- structure(list(time_to_event_yearmonth = c(90, 80, 89, 78, 8, 
96), dfs_event = c(0, 0, 0, 0, 1, 0), restaging = c("ND", "D", 
"D", NA, NA, "D"), follow_up = c("D", "D", "ND", "ND", "D", "D"
)), row.names = c(NA, -6L), class = "data.frame")
1
  • hi, thanks for the comment but how can i resolve it? Commented Aug 2, 2023 at 17:09

1 Answer 1

1

You shouldn't use this kind of syntax here. Replace the survfit2 call with

p <- survfit2(Surv(time_var) ~ group_var, data = data_in) %>% ...

and call your function by explicitly specifying df_test:

plt_survive(
    data_in = df_test,
    time_var = df_test$time_to_event_yearmonth,
    event_var = df_test$dfs_event,
    group_var = df_test$restaging
)

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.