[Rd] specials and ::

Bill Dunlap w||||@mwdun|@p @end|ng |rom gm@||@com
Mon Aug 26 18:35:55 CEST 2024


One could define a function that removes all instances of 'survival::' from
an expression, returning the fixed up expression, and applying it to all
formulae given as arguments to your survival functions.  E.g.,

removeDoubleColonSurvival <- function (formula)
{
  doubleColon <- as.name("::")
  survival <- as.name("survival")
  fix <- function(expr) {
    if (is.call(expr) && identical(expr[[1]], doubleColon) &&
identical(expr[[2]], survival)){
      expr <- expr[[3]]
    } else if (is.call(expr)) {
      for(i in seq_along(expr)){
        expr[[i]] <- fix(expr[[i]])
      }
    }
    expr
  }
  fix(formula)
}

identical(f(y ~ f(x) + survival::g(x,10) + z),
                  y ~ f(x) + g(x,10) + z)
# [1] TRUE

-Bill

On Mon, Aug 26, 2024 at 7:42 AM Therneau, Terry M., Ph.D. via R-devel <
r-devel using r-project.org> wrote:

> The survival package makes significant use of the "specials" argument of
> terms(), before
> calling model.frame; it is part of nearly every modeling function. The
> reason is that
> strata argments simply have to be handled differently than other things on
> the right hand
> side. Likewise for tt() and cluster(), though those are much less frequent.
>
> I now get "bug reports" from the growing segment that believes one should
> put
> packagename:: in front of every single instance.   For instance
>        fit <- survival::survdiff( survival::Surv(time, status) ~ ph.karno
> +
> survival::strata(inst),  data= survival::lung)
>
> This fails to give the correct answer because it fools terms(formula,
> specials=
> "strata").    I've stood firm in my response of "that's your bug, not
> mine", but I begin
> to believe I am swimming uphill.   One person responded that it was
> company policy to
> qualify everything.
>
> I don't see an easy way to fix survival, and even if I did it would be a
> tremendous amout
> of work.   What are other's thoughts?
>
> Terry
>
>
>
> --
>
> Terry M Therneau, PhD
> Department of Quantitative Health Sciences
> Mayo Clinic
> therneau using mayo.edu
>
> "TERR-ree THUR-noh"
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-devel using r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

	[[alternative HTML version deleted]]



More information about the R-devel mailing list