[R] character variables in substitute()
Eik Vettorazzi
E.Vettorazzi at uke.uni-hamburg.de
Tue Feb 2 11:37:23 CET 2010
Hi David,
there is a solution using bquote instead of substitute
expr<-bquote(italic(.(pname[1]))==.(params[1])~",
"~.(as.name(pname[2]))==.(params[2]))
plot(1,1,main=expr)
hth.
dkStevens schrieb:
> In trying to create a plotmath expression for plot labeling, such as
>
> R = 6, beta = 15
>
> where I want beta to be the Greek beta and, possibly, R in italics (like one
> would get in an explicit expression. The reason for this is that I want to
> write a string builder function that takes vectors of variable names and
> their values and return a plotmath expression for labeling a plot. One
> approach I tried is
>
> pname = c("R","beta")
> params = c(6,15)
> substitute(p == v,list(p = pname[i],v = format(params[i],digits=4))
>
> but this just copies the character strings in pname into the expression. Can
> anyone help me do what I want? How would I manage passing the resulting
> string back to the calling routine? Any help will be much appreciated.
>
>
>
--
Eik Vettorazzi
Institut für Medizinische Biometrie und Epidemiologie
Universitätsklinikum Hamburg-Eppendorf
Martinistr. 52
20246 Hamburg
T ++49/40/7410-58243
F ++49/40/7410-57790
More information about the R-help
mailing list