Others have shown you ways to do what you asked, and what you asked happens
to also be FAQ 7.22 (but with terms different enough that that FAQ is not
obvious).

However the solutions that you are tending towards are running into the
problems addressed in fortune(106) and fortune(236), the solutions are
getting complex, prone to error or worse problems.

Can you tell us more about what you are trying to accomplish?  There may be
a much simpler solution than the approach that you are trying.

For example it may greatly simplify things if you store some of your
objects in a list rather than the global environment and worked with them
there:


> doppel <- list()
> doppel$aa <- 3.1416
> doppel$bb  <- function(x) {x^2}
> r <- 2
> xx <- c("aa", "bb")
>
> out <- doppel[[ xx[1] ]] * doppel[[ xx[2] ]](r)
> out
[1] 12.5664
>
> doppel[[ paste( 'a','a', sep='' ) ]] <- 3
>
> doppel$aa
[1] 3
> with(doppel, aa)
[1] 3



On Sat, Nov 3, 2012 at 3:31 PM, andrewH <ahoerner@rprogress.org> wrote:

> Dear folks--
>
> Suppose I have an expression that evaluates to a string, and that that
> string, were it not a character vector, would be a symbol.  I would like a
> function, call it doppel(), that will take that expression as an argument
> and produce something that functions exactly like the symbol would have if
> I
> typed it in the place of the function of the expression.  It should go as
> far along the path to evaluation as the symbol would have, and then stop,
> and be available for subsequent manipulation.  For example, if
>
> aa <- 3.1416
> bb  <- function(x) {x^2}
> r <- 2
> xx <- c("aa", "bb")
>
> out <- doppel(xx[1])*doppel(xx[2])(r)
>
> Then out should be 13.3664
>
> Or similarly, after
> doppel(paste("a",  "a",  sep=''))  <-  3
> aa
>
> typing aa should return 3.
>
> Is there such a function? Can there be?
>
> I thought as.symbol would do this, but it does not.
> > as.symbol (xx[1])*as.symbol (xx[2])(r)
> Error: attempt to apply non-function
>
> Looking forward to hearing from y'all.    --andrewH
>
>
>
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/Can-you-turn-a-string-into-a-working-symbol-tp4648343.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help@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.
>



-- 
Gregory (Greg) L. Snow Ph.D.
538280@gmail.com

	[[alternative HTML version deleted]]


