[R] Varying texts in expression(paste())
Winfried Theis
theis at statistik.uni-dortmund.de
Fri Jan 31 14:54:02 CET 2003
Hi,
I had a similar problem last year and Thomas Lumley helped me a lot on this. I
needed to replace some variables by their values in a quite complicated text
expression. Here is what Thomas suggested:
<quote Thomas Lumley on>
In your example you wanted b and c to be elements of a vector. They
actually have to be elements of a list
> c(quote(beta),quote(gamma^3))
[[1]]
beta
[[2]]
gamma^3
So
expr1<-quote(alpha)
expr2<-c( quote(beta), quote(gamma^3))
plot(1:10,main=substitute("Estimated "*a*" for "*b*" vs."*c,
list(a=expr1,b=expr2[[1]],c=expr2[[2]])))
Finally, you could even make the expressions from text strings if you want
to
str1<-"alpha"
str2<-c("beta","gamma^3")
expr1<-parse(text=str1)[[1]]
expr2<-parse(text=str2)
plot(1:10,main=substitute("Estimated "*a*" for "*b*" vs."*c,
list(a=expr1,b=expr2[[1]],c=expr2[[2]])))
<quote Thomas Lumley off>
For full details see (and this is worthwhile!) the thread "[R] Constructing
titles from list of expressions" from August 7, 2002.
Thanks again to Thomas,
Winfried
---------------------------------------------------------------------
E-Mail: Winfried Theis <theis at statistik.uni-dortmund.de>
Date: 31-Jan-03
Dipl.-Math. Winfried Theis
SFB 475, Fachbereich Statistik, Universit"at Dortmund, 44221 Dortmund
Tel.: +49-231-755-5903 FAX: +49-231-755-4387
----------------------------------------------------------------------
More information about the R-help
mailing list