From pdalgd at gmail.com  Wed Mar 20 13:28:10 2013
From: pdalgd at gmail.com (peter dalgaard)
Date: Wed, 20 Mar 2013 13:28:10 +0100
Subject: [Rd] Deprecating partial matching in $.data.frame
Message-ID: <A0DE2631-213D-4DB2-A952-5DBFA7A7F14C@gmail.com>

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



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