[R] How to execute a funcition which name is stored in a string?
Henrik Bengtsson
hb at stat.berkeley.edu
Mon Nov 2 08:17:20 CET 2009
?do.call
/H
On Sun, Nov 1, 2009 at 10:58 PM, Charlie Sharpsteen
<chuck at sharpsteen.net> wrote:
> On Sun, Nov 1, 2009 at 8:07 PM, Ning Ma <pningma at gmail.com> wrote:
>>
>> Hi, everybody
>>
>> Is there any way to execute a function, which name is stored in a string.
>> such as:
>> a <- "ls()"
>> foo(a) ## same as ls() itself.
>
> One way to accomplish this by using get() to search for a function
> that matches your string. You can assign the return value of get() to
> a variable which may be used like the original function object:
> a <- 'ls'
> foo <- get( a, mode = 'function' )
> foo()
> [1] "a" "foo"
>
>
>
> -Charlie
>
> ______________________________________________
> 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.
>
More information about the R-help
mailing list