[R] How to use expression(italic()) in a "vectorized" way (within a function)?

Marius Hofert m_hofert at web.de
Fri Nov 26 09:30:49 CET 2010

Dear expeRts,

I would like to use expression() for creating labels in a splom, as shown in the 
first minimal example below. Is there any way I can simplify having to write 
"expression(italic(...))" several times?
The second example is what I tried so far, but I can't manage to get italic() to
work. Moreover, it still seems bulky...



## minimal example (working but bulky)
U <- matrix(runif(900),ncol=3)
lattice::splom(~U[,1:3],varnames = c(expression(italic(U[1])),expression(italic(U[2])),expression(italic(U[3]))))

## also bulky (and does not incorporate italic())
f <- function(x){
    do.call(expression, lapply(1:3, function(j) substitute(x[y], list(x = as.name(x), y = 0+j))))
lattice::splom(~U[,1:3],varnames = f("U"))

More information about the R-help mailing list