[Rd] specials issue, a heads up
pd@|gd @end|ng |rom gm@||@com
Mon Feb 24 20:53:14 CET 2020
Notice that the stats package contains the same issue: For some reason it defines an offset() function (for no particular reason, afaics) which just returns its argument. So
> x <- rnorm(10)
> y <- z <- 1:10
lm(formula = x ~ y + offset(z))
lm(formula = x ~ y + stats::offset(z))
(Intercept) y stats::offset(z)
0.82531 -0.08397 NA
So I'm inclined to say that formulas are formulas and functions using formulas interpret functions and operators at their own convenience. You also deserve what you get from
lm(formula = x ~ base::`+`(y, z))
(Intercept) base::`+`(y, z)
> On 24 Feb 2020, at 19:21 , Duncan Murdoch <murdoch.duncan using gmail.com> wrote:
> On 24/02/2020 8:55 a.m., Therneau, Terry M., Ph.D. via R-devel wrote:
>> I recently had a long argument wrt the survival package, namely that the following code
>> didn't do what they expected, and so they reported it as a bug
>> survival::coxph( survival::Surv(time, status) ~ age + sex + survival::strata(inst),
>> a. The Google R style guide recommends that one put :: everywhere
>> b. This breaks the recognition of cluster as a "special" in the terms function.
>> I've been stubborn and said that their misunderstanding of how formulas work is not my
>> problem. But I'm sure that the issue will come up again, and multiple other packages
>> will break.
>> A big problem is that the code runs, it just gives the wrong answer.
> I don't know how widely used survival::strata is versus the special strata (or cluster, or other specials). If you were just introducing this now, I'd try to make sure that only one of those worked: don't have any functions matching the names of specials, or have functions that generate an error if you call them. I did that in the much less widely used "tables" package, e.g. Heading() has special interpretation, and the Heading function is defined as
> Heading <- function(name = NULL, override = TRUE,
> character.only = FALSE,
> nearData = TRUE)
> stop("This is a pseudo-function, not meant to be called.")
> However, survival has far more users than tables does, so changing the name of your special functions or the corresponding regular functions could be a huge headache.
> Perhaps there's a way to set a flag before evaluating the function in the formula, and generate a warning if survival::strata is called when it looks like the special function is intended.
> Duncan Murdoch
> R-devel using r-project.org mailing list
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Office: A 4.23
Email: pd.mes using cbs.dk Priv: PDalgd using gmail.com
More information about the R-devel