From P.Dalgaard at biostat.ku.dk  Thu Jul 19 13:31:56 2007
From: P.Dalgaard at biostat.ku.dk (Peter Dalgaard)
Date: Thu, 19 Jul 2007 13:31:56 +0200
Subject: [Rd] substitute and expression (Peter Dalgaard)
In-Reply-To: <BC3864C7-8742-4E1D-B3C1-12161A6E3A27@anu.edu.au>
References: <mailman.8.1184752806.18649.r-devel@r-project.org>
	<BC3864C7-8742-4E1D-B3C1-12161A6E3A27@anu.edu.au>
Message-ID: <469F4BAC.7050202@biostat.ku.dk>

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



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