Message-ID: <806322fe0911012258m674316f0hb1a88c07d70a0e8a@mail.gmail.com>
Date: 2009-11-02T06:58:43Z
From: Charlie Sharpsteen
Subject: How to execute a funcition which name is stored in a string?
In-Reply-To: <80831da90911012007g6e311428p3eb41643cdc0c64c@mail.gmail.com>
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