[R] Using bquote: question

Bert Gunter gunter.berton at gene.com
Fri Jan 25 04:37:18 CET 2008


It's a bit subtle, I must admit,  but this behavior **is** documented ( ya
just gotta read **carefully**).

Your first (S3) plot statement calls plot.default. The "main" argument
matches the "main" argument of plot.default and works as you expect,
plotting the expression character string that results from  paste() using
the plotmath functionality.

However, your 2nd plot call calls plot.formula, and the Help for that tells
us that the ... argument gets evaluated in the parent.frame(), which in this
case is the global environment. But

bquote( paste( p==.(p)," and ",phi==.(phi)) )

in the global environment is just:

paste(p == 2, " and ", phi == 1) 
 evaluated in the global environment, and since p==2 and phi==1 are both
TRUE there, the paste function becomes
"TRUE and TRUE", which is what you got.

Whether this is "nice" behavior or not I cannot say (because I don't know
enough about the ins and outs of computer languages). But I do appreciate
that the folks who develop and maintain the core R language do such a
careful job of documenting things that even dolts like me can figure it out
if we make the effort.

Cheers,
Bert Gunter





-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
Behalf Of Schools Statistics Poster Competition
Sent: Thursday, January 24, 2008 5:58 PM
To: R-help mailing list
Subject: [R] Using bquote: question

Hi all

Observe:

x <- c(1,2)
y <- c(1,-1)

phi <- 1
p <- 2

par( mfrow=c(1,2))
plot(x , y, main=bquote( paste( p==.(p)," and ",phi==.(phi)) ) )
plot(y ~ x, main=bquote( paste( p==.(p)," and ",phi==.(phi)) ) )
par( mfrow=c(1,2))


On my system (details below), the first plot is correct (in my 
understanding), and produces a title reading "p=2 and phi=1" (with 
appropriate Greek for phi).

However, the second produces the title "TRUE and TRUE".

Is this a bug, or a misunderstanding or my part(in which case, I'm 
sure I'll be told the obscure location where this is documented!)?

Thanks.

P.


> sessionInfo()
R version 2.6.0 (2007-10-03)
i486-pc-linux-gnu

locale:
LC_CTYPE=en_AU.UTF-8;LC_NUMERIC=C;LC_TIME=en_AU.UTF-8;LC_COLLATE=en_AU.UTF-8
;LC_MONETARY=en_AU.UTF-8;LC_MESSAGES=en_AU.UTF-8;LC_PAPER=en_AU.UTF-8;LC_NAM
E=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_AU.UTF-8;LC_IDENTIFICATION
=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] tweedie_1.5.3 statmod_1.3.0

loaded via a namespace (and not attached):
[1] rcompgen_0.1-15
>


This email (including any attached files) is confidentia...{{dropped:15}}

______________________________________________
R-help at 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.



More information about the R-help mailing list