[R] expression(), mixed symbols and evaluated objects

2010-03-10 Thread Markus Loecher
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.

Thanks,

Markus

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] expression(), mixed symbols and evaluated objects

2010-03-10 Thread Duncan Murdoch

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

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.