Re: [Rd] Bug in subsetting data frame (PR#13515)

From: Duncan Murdoch <murdoch_at_stats.uwo.ca>
Date: Tue, 10 Feb 2009 08:31:47 -0500

Stavros Macrakis wrote:
> Don't know if this is the problem, but....
>
> It is a bad idea to set data.frame <- xxx since R has a single
> namespace for functions and variables.
>
That's not quite accurate. R mixes functions and variables in namespaces, but it has lots of namespaces, and it usually doesn't cause much trouble to have a variable named data.frame in one, and a function named data.frame in another. The evaluator recognizes the context of usage and will get the function for a function call. If you retrieve data.frame without doing a function call, you'll get whichever one it finds first, which is typically the one in the global environment, as below. Sometimes this causes trouble (e.g. if you passed data.frame to apply or do.call), but usually not, and I don't think it would cause
trouble below. What we see below is a simple misunderstanding of the difference between [] and $.

Duncan Murdoch

> -s
>
> On 2/10/09, xinlee883@stat.math.ethz.ch <xinlee883@stat.math.ethz.ch> wrote:
>
>> Full_Name: Xin Lee
>> Version: 2.8.0
>> OS: Windows XP
>> Submission from: (NULL) (193.200.150.23)
>>
>>
>> Dear developer
>>
>> I discover annoying bug in subsetting data frame. Here is reproducable
>> examples:
>>
>>
>>> data.frame <- data.frame(x = runif(5), y = runif(5), row.names =
>>>
>> c('a','b','c','d','e')
>>
>>
>>> subset <- data.frame['x']
>>> subset['a',]
>>>
>> work
>>
>>
>>> subset <- data.frame$x
>>> subset['a',]
>>>
>> not work
>>
>>
>>> subset <- data.frame['a',]
>>> subset[,'x']
>>>
>> work
>>
>>
>>> subset <- data.frame[,'x']
>>> subset['a',]
>>>
>> not work
>>
>> I hope this is easy fix for you and works corectly soon.
>>
>> Sincerely,
>> Xin Lee
>>
>> ______________________________________________
>> R-devel_at_r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>
>>
>
> ______________________________________________
> R-devel_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Tue 10 Feb 2009 - 12:39:59 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 10 Feb 2009 - 14:30:21 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive