openpharma/visR

Add check that 'survfit' object was created with `estimate_KM()`

Closed this issue · 0 comments

When a survfit object is created with estimate_KM() additional information is added to the output object. But we still return the object as class 'survift'. The consequences of this is that users could create survfit objects with survival::survfit(); they could pass this object to any visR S3 method for survfit objects, but there is a good chance there is an error.

I suggest one of the following:

  1. Add the class c("visr_survfit", "survfit") to objects created with estimate_KM() and updated all S3 methods from get_pvalue.survfit() to get_pvalue.visr_survfit(), for example. This solution is the most in-line with how most users would expect a function to work, I think.
  2. Write a simple internal function that checks if the survift object was created with visR and print a warning if it was not. Example below
is_visr_survfit <- function(x) {
  rlang::is_quosure(x$call)
}

visR::estimate_KM(visR::adtte, strata = "TRTA") |> 
  is_visr_survfit()
#> [1] TRUE

survival::survfit(survival::Surv(AVAL, 1 - CNSR) ~ TRTA, visR::adtte) |> 
  is_visr_survfit()
#> [1] FALSE

Created on 2022-05-08 by the reprex package (v2.0.1)

I don't think this is a priority and can wait until after the next CRAN release.