Skip to content

Commit

Permalink
Merge pull request rstudio#3373 from rstudio/nested-quo-to-func
Browse files Browse the repository at this point in the history
  • Loading branch information
wch authored Apr 27, 2021
2 parents 1558c84 + cf0a865 commit c2232ae
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ shiny 1.6.0.9000

### Bug fixes

* Closed #3374: `quoToFunction()` now works correctly with nested quosures; and as a result, quasi-quotation with rendering function (e.g., `renderPrint()`, `renderPlot()`, etc) now works as expected with nested quosures. (#3373)

* Exported `register_devmode_option()`. This method was described in the documentation for `devmode()` but was never exported. See `?devmode()` for more details on how to register Shiny Developer options using `register_devmode_option()`. (#3364)

### Library updates
Expand Down
7 changes: 4 additions & 3 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -538,9 +538,10 @@ installExprFunction <- function(expr, name, eval.env = parent.frame(2),
#' @export
quoToFunction <- function(q, label, ..stacktraceon = FALSE) {
q <- as_quosure(q)
# Use new_function() instead of as_function(), because as_function() adds an
# extra parent environment. (This may not actually be a problem, though.)
func <- new_function(NULL, get_expr(q), get_env(q))
func <- as_function(q)
# as_function returns a function that takes `...`. We want one that takes no
# args.
formals(func) <- list()
wrapFunctionLabel(func, label, ..stacktraceon = ..stacktraceon)
}

Expand Down
12 changes: 12 additions & 0 deletions tests/testthat/test-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -239,3 +239,15 @@ test_that("dateYMD works", {
c("2019/11/05", "")
)
})

test_that("quoToFunction handles nested quosures", {
quo_inner <- local({
x <- 1
rlang::quo(x)
})

quo_outer <- rlang::quo(!!quo_inner + 1)

func <- quoToFunction(quo_outer, "foo")
expect_identical(func(), 2)
})

0 comments on commit c2232ae

Please sign in to comment.