Message-ID: <1113436792.9106.29.camel@horizons.localdomain>
Date: 2005-04-13T23:59:52Z
From: Marc Schwartz
Subject: Map a string to an object
In-Reply-To: <10dee4690504131646374ea0c4@mail.gmail.com>
On Wed, 2005-04-13 at 19:46 -0400, Fernando Saldanha wrote:
> Is there a way in R to get an object whose name is given by a string?
>
> That is, like a function getObject(mystring) such that
>
> getObject('astring')
>
> returns the object astring (assuming it exists)?
>
> Thanks.
Yep. You are close.
See ?get
> x <- 1:10
> get("x")
[1] 1 2 3 4 5 6 7 8 9 10
> get("ls")
function (name, pos = -1, envir = as.environment(pos), all.names =
FALSE,
pattern)
{
if (!missing(name)) {
nameValue <- try(name)
...
HTH,
Marc Schwartz