[R] How to concatenate expressions
Sebastien Bihorel
Sebastien.Bihorel at cognigencorp.com
Fri Nov 20 17:19:29 CET 2009
Dear R-users,
I am developing a plotting function, which receives expressions and
character/numerical vectors as part of the many input arguments and
which tries to concatenate them before displaying the result to the
plot. I currently cannot find a way to make this concatenation works. I
have read several posts in the list that solved this problem by pasting
the different elements together before creating the expressions (like in
http://tolstoy.newcastle.edu.au/R/help/02a/4790.html). I cannot
implement this solution because my expressions and numerical/character
vectors are passed to the function and not create inside the function. I
would greatly appreciate any help with the following example code.
Thank you
testplot <- function(a,b,c) {
text <- as.expression(paste(a,b,c,sep=' '))
dev.new()
plot(-5:5,-5:5,col=0)
for (i in 1:3) {
text(x=i,
y=i,
labels=text[i])
}
}
a <- as.expression(c(bquote(alpha),bquote(beta),bquote(gamma)))
b <- as.expression(1:3)
c <- as.expression(c(bquote('-10'^th),
bquote('-20'^th),
bquote('-30'^th)))
testplot(a,b,c)
More information about the R-help
mailing list