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

From: Stavros Macrakis <macrakis_at_alum.mit.edu>
Date: Tue, 10 Feb 2009 09:51:58 -0500

On Tue, Feb 10, 2009 at 8:31 AM, Duncan Murdoch <murdoch_at_stats.uwo.ca>wrote:

> Stavros Macrakis wrote:
>
>> 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.
>

Interesting. I was not aware of this rule.

Can you point me to chapter and verse in the language definition ( http://cran.r-project.org/doc/manuals/R-lang.html)? I couldn't find it, but I probably looked in the wrong place.

| Sometimes this causes trouble (e.g. if you passed data.frame to apply or do.call), but usually not, ...

Indeed! It is quite surprising that functions are defined using ordinary assignment, but function lookup is different from normal variable evaluation, e.g. that after c<-4, c(10) is different from (c)(10). Was this inspired by some other language? I don't think it's done this way in any other language I can think of....

          -s

        [[alternative HTML version deleted]]



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Tue 10 Feb 2009 - 14:10:04 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