[R] Distinguishing variables from functions with the same name

Wacek Kusnierczyk Waclaw.Marcin.Kusnierczyk at idi.ntnu.no
Fri Feb 13 17:45:34 CET 2009


Stavros Macrakis wrote:
> On Fri, Feb 13, 2009 at 10:47 AM, Gabor Grothendieck
> <ggrothendieck at gmail.com> wrote:
>   
>> See ?get and try:
>>     
>
> Interesting.  I hadn't paid attention to the 'mode' argument before.
>
> Where would it be advisable to use anything but mode='any' or mode='function'?
>
>   

don't know if it really is advisable, but you can imagine a scenario
where you have different-moded like-named variables within nested
scopes, e.g.:

x = TRUE
local({
    x = 0;
    local({
       x = 'foo';
       list(get('x'), get('x', mode='numeric'), get('x',
mode='logical')) }) })
# list('foo', 0, TRUE)

basically, you want, within a scope, the value of a variable named 'x'
from in the closest environment in which it has the given type of value.

vQ




More information about the R-help mailing list