Re: [Rd] substitute and expression (Peter Dalgaard)

From: Peter Dalgaard <P.Dalgaard_at_biostat.ku.dk>
Date: Thu, 19 Jul 2007 13:31:56 +0200

John Maindonald wrote:
> In this connection, note the following
>
> > a4 <- 4
> > plotThis <- bquote(alpha==.(a), list(a=a4))
> > do.call(plot, list(1:10, main=do.call(expression, c(plotThis))))
> > do.call(plot, list(1:10, main=do.call(expression, plotThis)))
> Error in do.call(expression, plotThis) : second argument must be a list
>
> > ## Whereas plotThis has class "call", c(plotThis) has class "list"
> > class(plotThis)
> [1] "call"
> > class(c(plotThis))
> [1] "list"
>
> > ## Thus, the following is possible:
> > do.call(plot, list(1:10, main=do.call(expression, list(plotThis))))
>
>
> Marc Schwartz pointed out to me., some considerable time ago,
> that one could use bquote() and .() to create the elements of a
> list object whose elements can be plotted in parallel as required,
> e.g., for axis labels, thus:
>
> > plot(1:2, 1:2, xaxt="n")
> > arg1 <- bquote(""< .(x), list(x=1.5))
> > arg2 <- bquote("">= .(x), list(x=1.5))
> > axis(1, at=1:2, labels=do.call(expression, list(arg1, arg2)))
>
> For a unified approach to use of do.call(expression, ...), maybe
> one should use bquote() and .()?
>
>
I think I'd prefer as.expression() in both cases:

do.call(plot, list(1:10, main=as.expression(plotThis)))

axis(1, at=1:2, labels=as.expression(list(arg1, arg2)))

-- 
   O__  ---- Peter Dalgaard             Ă˜ster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark          Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard_at_biostat.ku.dk)                  FAX: (+45) 35327907

______________________________________________
R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Thu 19 Jul 2007 - 11:38:53 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 19 Jul 2007 - 19:36:45 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.