Hi, Is this expected behavior (R-3.6.0)? dat <- cbind(x = 1:10, y = 10:1) ylab <- substitute(X[t], list(t = 2)) plot(dat, ylab = ylab) # works (correctly displays ylab) boxplot(dat, ylab = ylab) # fails boxplot(dat, ylab = as.expression(ylab)) # works Thanks & cheers, M
It's not new anyway. You see the same behaviour with boxplot(dat, ylab=quote(X[2])) and it boils down to the use of do.call("bxp", ...) in the internals. As a general matter, expression() exists to prevent this sort of confusion, e.g., in this construction,> X <- quote(Y+1); bquote(f(.(X)))f(Y + 1) is indistinguishable from just entering f(Y+1), so f has no way of detecting whether or not it is intended to evaluate Y + 1. The same thing is happening with do.call: call objects are being "spliced into" the generated call, and if they are not protected with expression, you have the trouble. I don't know whether it is worth trying to change this. You know the workaround. -pd> On 27 Mar 2020, at 02:55 , Marius Hofert <marius.hofert at uwaterloo.ca> wrote: > > Hi, > > Is this expected behavior (R-3.6.0)? > > dat <- cbind(x = 1:10, y = 10:1) > ylab <- substitute(X[t], list(t = 2)) > plot(dat, ylab = ylab) # works (correctly displays ylab) > boxplot(dat, ylab = ylab) # fails > boxplot(dat, ylab = as.expression(ylab)) # works > > Thanks & cheers, > M > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel-- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Office: A 4.23 Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com
iuke-tier@ey m@iii@g oii uiow@@edu
2020-Mar-27 12:59 UTC
[Rd] [External] Re: Expressions from boxplot() passed to bxp()
On Fri, 27 Mar 2020, peter dalgaard wrote:> It's not new anyway. You see the same behaviour with > > boxplot(dat, ylab=quote(X[2])) > > and it boils down to the use of do.call("bxp", ...) in the internals. > > As a general matter, expression() exists to prevent this sort of confusion, e.g., in this construction, > >> X <- quote(Y+1); bquote(f(.(X))) > f(Y + 1) > > is indistinguishable from just entering f(Y+1), so f has no way of detecting whether or not it is intended to evaluate Y + 1. The same thing is happening with do.call: call objects are being "spliced into" the generated call, and if they are not protected with expression, you have the trouble.do.call has a 'quote' argument that can be used to address this. The default is quote = FALSE, which means all arguments will be evaluated by the called function. Which is fine for arguments that evaluate to themselves. For symbols and calls it isn't. I did try to make the case some time ago that quote = TRUE should be the default but I lost that argument. It might be worth revisiting that, or at least reviewing the uses of do.call in our code sometime (there are a couple of hundred). Best, luke> > I don't know whether it is worth trying to change this. You know the workaround. > > -pd > > > >> On 27 Mar 2020, at 02:55 , Marius Hofert <marius.hofert at uwaterloo.ca> wrote: >> >> Hi, >> >> Is this expected behavior (R-3.6.0)? >> >> dat <- cbind(x = 1:10, y = 10:1) >> ylab <- substitute(X[t], list(t = 2)) >> plot(dat, ylab = ylab) # works (correctly displays ylab) >> boxplot(dat, ylab = ylab) # fails >> boxplot(dat, ylab = as.expression(ylab)) # works >> >> Thanks & cheers, >> M >> >> ______________________________________________ >> R-devel at r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-devel > >-- Luke Tierney Ralph E. Wareham Professor of Mathematical Sciences University of Iowa Phone: 319-335-3386 Department of Statistics and Fax: 319-335-3017 Actuarial Science 241 Schaeffer Hall email: luke-tierney at uiowa.edu Iowa City, IA 52242 WWW: http://www.stat.uiowa.edu
Seemingly Similar Threads
- Expressions from boxplot() passed to bxp()
- Seed in 'parallel' vignette
- R process killed when allocating too large matrix (Mac OS X)
- boxplot and bxp do not respect xlim by default (PR#9754)
- parallel::detectCores(TRUE) gives: Error in system(cmd, TRUE) : error in running command