From pdalgd at gmail.com  Wed Mar 20 17:26:58 2013
From: pdalgd at gmail.com (peter dalgaard)
Date: Wed, 20 Mar 2013 17:26:58 +0100
Subject: [Rd] Deprecating partial matching in $.data.frame
In-Reply-To: <E66794E69CFDE04D9A70842786030B931B918849@PA-MBX04.na.tibco.com>
References: <A0DE2631-213D-4DB2-A952-5DBFA7A7F14C@gmail.com>
	<E66794E69CFDE04D9A70842786030B931B918849@PA-MBX04.na.tibco.com>
Message-ID: <A3631670-5E8D-48DC-9868-8C9EE8852FE6@gmail.com>


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



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