[R] expression(), mixed symbols and evaluated objects
Duncan Murdoch
murdoch at stats.uwo.ca
Wed Mar 10 15:12:06 CET 2010
On 10/03/2010 8:52 AM, Markus Loecher wrote:
> Is it possible to mix symbols and evaluated objects inside the expression()
> function ?
> The following example shows what I am trying to achieve:
>
> for (m in 1:3) {
> plot(1:10); #just a place holder for the real plots
> title(expression(y = m * lambda));
> }
>
> I want to actually evaluate the variable m but keep lambda as a symbol in
> the title.
> I tried to wrap an eval() around various subparts of the expression but to
> no avail.
>
> Going further, I ideally would like to mix text into the expression as well.
>
> Any help would be appreciated.
Use bquote. It returns an expression after evaluating only the parts
wrapped in ".()". For example,
for (m in 1:3) {
plot(1:10); #just a place holder for the real plots
title(bquote(y == .(m) * lambda));
}
Duncan Murdoch
More information about the R-help
mailing list