[R] converting strings to expressions

Deepayan Sarkar deepayan.sarkar at gmail.com
Thu Sep 14 21:31:51 CEST 2006


Hi,

consider this:

--------------

estr <- c("2^4", "alpha[1]")
eexp <- expression(2^4, alpha[1])


## Is it possible to get 'eexp' starting from 'estr'? The closest I could
## get was:

do.call(expression, lapply(estr, as.name))

## but it is not quite the same; e.g. the following behave differently:

library(lattice)

xyplot(1:10 ~ 1:10,
       scales = list(x = list(at = c(3, 6), labels = eexp)))

xyplot(1:10 ~ 1:10,
       scales = list(x = list(at = c(3, 6),
                     labels = do.call(expression,
                     lapply(estr, as.name)))))

---------------

This happens in both 2.3.1 and pre-2.4.0.

Deepayan


> sessionInfo()
Version 2.3.1 Patched (2006-08-27 r39012)
x86_64-unknown-linux-gnu

attached base packages:
[1] "methods"   "stats"     "graphics"  "grDevices" "utils"     "datasets"
[7] "base"

other attached packages:
  lattice
"0.13-10"

> sessionInfo()
R version 2.4.0 Under development (unstable) (2006-08-30 r39022)
x86_64-unknown-linux-gnu

locale:
C

attached base packages:
[1] "methods"   "stats"     "graphics"  "grDevices" "utils"     "datasets"
[7] "base"

other attached packages:
 lattice
"0.14-3"



More information about the R-help mailing list