Skip to content

use of bquote

6 messages · William Dunlap, Rolf Turner, Peter Dalgaard +2 more

#
When I use run this expression

a <- 2; b <- 3; xyplot(1:10 ~ a*(1:10), sub = c(bquote(a == .(a) ~ b==.(b))))

the subtitle contains three copies of the "a = 2  b = 3" phrase.
Why does it do that?  How do I tell it to give me only one copy?

Rich
#
To avoid it don't wrap bquote() with c().  The following does what you asked for:
    a <- 2; b <- 3; xyplot(1:10 ~ a*(1:10), sub = bquote(a == .(a) ~ b==.(b)))

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com
#
On 11/22/13 18:47, William Dunlap wrote:
Not for me it doesn't.  Without the c() wrapper, I get no subtitle at 
all.  Your recipe seems to
work with base graphics and plot() but not with lattice and xyplot().  
Also the c() wrapper
seems to have no impact when used with plot().

Moreover I am mystified by the impact of the c() wrapper when used with 
xyplot().

The result returned by bquote() has class "call".  The result returned 
by c(bquote(...)) is a
list, of length 1, whose sole entry is of class "call" and is, as one 
might expect, equal to the
result returned by bquote().

But why should passing this length-1 list as the value for "sub" cause a 
triplication of the
subtitle?

     cheers,

     Rolf
#
On 22 Nov 2013, at 07:53 , Rolf Turner <r.turner at auckland.ac.nz> wrote:

            
I dunno either, but a hint at the reason would be to look at what happens with

xyplot(0 ~ 1, sub=list(quote(1+1)))

When you do computing on the language, sometimes quote()?ing is not sufficient protection against evaluation. That?s what expression objects are for. 

A solution seems to be

xyplot(0 ~ 1, sub=as.expression(
	bquote(pi==.(pi) ~ e==.(exp(1)))
))
#
On Nov 22, 2013, at 12:14 AM, peter dalgaard wrote:

            
I had an email exchange with Deepayan a few years ago and he rightly said that the docs stated that the arguments to xlab, ylab, sub and main were supposed to be unevaluated _expressions_ . Neither `bquote` nor `substitute` return values as such:
[1] FALSE
[1] FALSE
--

David Winsemius
Alameda, CA, USA
#
Peter,

thank you.  this is perfect.  I have been looking for this idiom for years.

xyplot(0 ~ 1, sub=as.expression(
        bquote(pi==.(pi) ~ e==.(exp(1)))
))


Can you add this idiom to the examples in the ?plotmath page.
And perhaps also to the ?xyplot page

Rich
On Fri, Nov 22, 2013 at 3:14 AM, peter dalgaard <pdalgd at gmail.com> wrote: