Skip to content
Prev 62603 / 63424 Next

specials and ::

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 at r-project.org> wrote: