[Rd] substitute and expression (Peter Dalgaard)

Peter Dalgaard P.Dalgaard at biostat.ku.dk
Thu Jul 19 13:31:56 CEST 2007


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



More information about the R-devel mailing list