[Rd] Deprecating partial matching in $.data.frame
peter dalgaard
pdalgd at gmail.com
Wed Mar 20 17:26:58 CET 2013
On Mar 20, 2013, at 16:59 , William Dunlap wrote:
> Will you be doing the same for attribute names?
Not at this point.
>
>> options(prompt=with(version, paste0(language,"-",major,".",minor,"> ")))
> R-2.15.3> x <- structure(17, AnAttr="an attribute", Abcd="a b c d")
> R-2.15.3> attr(x, "A")
> NULL
> R-2.15.3> attr(x, "An")
> [1] "an attribute"
> R-2.15.3> attr(x, "Ab")
> [1] "a b c d"
>
> How will you deal with the common idiom of using is.null(x$n)
> to see if x has a compnent named "n"? One would not want
> a warning if x had a component called "nn".
Why not? If you were looking for x$n, you're getting the wrong answer.
>
> Bill Dunlap
> Spotfire, TIBCO Software
> wdunlap tibco.com
>
>
>> -----Original Message-----
>> From: r-devel-bounces at r-project.org [mailto:r-devel-bounces at r-project.org] On Behalf
>> Of peter dalgaard
>> Sent: Wednesday, March 20, 2013 5:28 AM
>> To: r-devel at r-project.org
>> Subject: [Rd] Deprecating partial matching in $.data.frame
>>
>> 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
>>
>> ______________________________________________
>> R-devel at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
--
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