Bug 16538 - bquote() with where=list() or pairlist() has unintended behavior
Summary: bquote() with where=list() or pairlist() has unintended behavior
Status: UNCONFIRMED
Alias: None
Product: R
Classification: Unclassified
Component: Language (show other bugs)
Version: R-devel (trunk)
Hardware: All All
: P5 minor
Assignee: R-core
URL:
Depends on:
Blocks:
 
Reported: 2015-09-18 13:41 UTC by Jim Hester
Modified: 2015-09-18 13:41 UTC (History)
0 users

See Also:


Attachments
Patch to fix the bquote behavior described (561 bytes, patch)
2015-09-18 13:41 UTC, Jim Hester
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jim Hester 2015-09-18 13:41:45 UTC
Created attachment 1914 [details]
Patch to fix the bquote behavior described

bquote() exhibits surprising behavior when a list(), data.frame(), or pairlist() is passed in the where argument and the name to be substituted is _not_ found in the list.

# object within bquote function is substituted
bquote(.(unquote), list())
# function (e)
# if (is.pairlist(e)) as.pairlist(lapply(e, unquote)) else if (length(e) <=
#     1L) e else if (e[[1L]] == as.name(".")) eval(e[[2L]], where) else # as.call(lapply(e,
#     unquote))
# objects in the search path substituted
bquote(.(plot), list())
# function (x, y, ...)  UseMethod("plot")

# objects in the global environment substituted
test <- 1
fun <- function() bquote(.(test), list())
fun()
# [1] 1

All of these problems stem from the fact that bquote calls eval() with the default enclos argument, which defaults to parent.frame() for lists and pairlists.

The attached patch calls eval with enclos = NULL, which properly throws errors in all the above cases.  I believe this argument is ignored when the envir argument is actually an environment, so bquote behavior when where is an envir is unchanged.