From murdoch at stats.uwo.ca  Tue Feb 10 16:11:58 2009
From: murdoch at stats.uwo.ca (Duncan Murdoch)
Date: Tue, 10 Feb 2009 10:11:58 -0500
Subject: [Rd] Bug in subsetting data frame (PR#13515)
In-Reply-To: <8b356f880902100651n79fa3b04x5754f79e8ac17658@mail.gmail.com>
References: <20090210102506.CB966282EF48@mail.pubhealth.ku.dk>	
	<8b356f880902100459n321c321ew1ee4ab3c9a7ddb0f@mail.gmail.com>	
	<499181C3.6000907@stats.uwo.ca>
	<8b356f880902100651n79fa3b04x5754f79e8ac17658@mail.gmail.com>
Message-ID: <4991993E.3010204@stats.uwo.ca>

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

No, I'm also unable to find it.
> | 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....
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



[Rd] Bug in subsetting data frame (PR#13515)
Duncan Murdoch