[Rd] Deprecating partial matching in $.data.frame

peter dalgaard pdalgd at gmail.com
Wed Mar 20 13:28:10 CET 2013


Allowing partial matching on $-extraction has always been a source of accidents. Recently, someone who shall remain nameless tried names(mydata) <- "d^2" followed by mydata$d^2. 

As variables in a data frame are generally considered similar to variables in, say, the global environment, it seems strange that foo$bar can give you the content of foo$bartender.

In R-devel (i.e., *not* R-3.0.0 beta, but 3.1.0-to-be) partial matches now gives a warning. 

Of course, it is inevitable that lazy programmers will have been using code like

> anova(fit1)$P
[1] 0.0008866369           NA
Warning message:
In `$.data.frame`(anova(fit1), P) : Name partially matched in data frame

and now get the warning during package checks. This can always be removed by spelling out the column name, as in

> anova(fit1)$`Pr(>F)`
[1] 0.0008866369           NA

or by explicitly specifying a partial match with

> anova(fit1)[["P", exact=FALSE]]
[1] 0.0008866369           NA


-- 
Peter Dalgaard, Professor
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd.mes at cbs.dk  Priv: PDalgd at gmail.com



More information about the R-devel mailing list