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

From: Duncan Murdoch <>
Date: Tue, 10 Feb 2009 10:11:58 -0500

Stavros Macrakis wrote:
> On Tue, Feb 10, 2009 at 8:31 AM, Duncan Murdoch <>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 (
> I couldn't find it, but
> I probably looked in the wrong place.

No, I'm also unable to find it.
> | Sometimes this causes trouble (e.g. if you passed data.frame to apply or
>, 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....

I think originally there was no difference, and it caused the obvious
trouble when people used variable names like t and c other short function names, so this was added. I don't remember whether the different lookup rules showed up first in R or S.

Duncan Murdoch mailing list Received on Tue 10 Feb 2009 - 14:16:54 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 - 21:30:27 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive