[R] getAnywhere

Prof Brian Ripley ripley at stats.ox.ac.uk
Wed Oct 15 03:47:56 CEST 2008


eval(substitute(getAnywhere(x), list(x=name)))

It's a standard (if advanced) code snippet from the ideas of 'computing on 
the language'.

getAnywhere is written the way it is because it is intended for 
interactive use, especially for frustrated users who can't find an object 
that appears in e.g. a traceback().

On Tue, 14 Oct 2008, Bastian A. wrote:

> Hi List,
>
> I am trying to look up an object using getAnywhere, where the object I
> am looking for is given by the _value_ of the variable I am looking
> for. Since getAnywhere calls substitue on its argument it is looking
> for an object with the name of the argument not its value. Is there a
> way to work around this, or do I have to make my own getAnywhere
> without the substitute?
>
> This is an example to clarify things:
>> a <- 1
>> name = "a"
>> getAnywhere(name) # the intend here is to find the object a with value 1 not the object name with value a
> A single object matching 'name' was found
> It was found in the following places
>  .GlobalEnv
> with value
>
> [1] "a" # I'd like to see a 1 here the value of a
>
>
>
> Regards,
> Bastian
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-help mailing list