[R] Using bquote: question

Prof Brian Ripley ripley at stats.ox.ac.uk
Fri Jan 25 07:46:50 CET 2008


BTW, this is not the behaviour of current versions (R-patched, R-devel, 
and 2.6.0 is not even the latest released version) of R, so the comment 
about updating in the posting guide applies.  From the NEWS file

         plot.formula() was not accepting expressions for annotations
         passed to title().  (PR#10525)

(and 'main' is one of those).

On Thu, 24 Jan 2008, Bert Gunter wrote:

> 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.
>
> ______________________________________________
> 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.
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-help mailing list