Skip to content

Commit

Permalink
exprToFunction() and installExprFunction() support quosures (#3472)
Browse files Browse the repository at this point in the history
Co-authored-by: Barret Schloerke <[email protected]>
Co-authored-by: Winston Chang <[email protected]>
Co-authored-by: Carson Sievert <[email protected]>
Co-authored-by: Joe Cheng <[email protected]>
  • Loading branch information
5 people authored Aug 3, 2021
1 parent f01dc9f commit 1b3ed88
Show file tree
Hide file tree
Showing 41 changed files with 819 additions and 1,049 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/rituals.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,9 @@ jobs:
if: github.event_name == 'push'
run: |
# Can't push to a protected branch
if [ -z "`git cherry`"]; then
if [ -z "`git cherry origin/master`"]; then
echo "Un-pushed commits:"
git cherry -v
git cherry -v origin/master
echo "\nCan not push to a protected branch. Exiting"
exit 1
fi
Expand Down
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,6 @@ export(stopApp)
export(strong)
export(submitButton)
export(suppressDependencies)
export(sustainEnvAndQuoted)
export(tabPanel)
export(tabPanelBody)
export(tableOutput)
Expand Down Expand Up @@ -399,6 +398,7 @@ importFrom(rlang,enquos)
importFrom(rlang,enquos0)
importFrom(rlang,eval_tidy)
importFrom(rlang,expr)
importFrom(rlang,fn_body)
importFrom(rlang,get_env)
importFrom(rlang,get_expr)
importFrom(rlang,inject)
Expand Down
20 changes: 10 additions & 10 deletions R/bind-cache.R
Original file line number Diff line number Diff line change
Expand Up @@ -292,11 +292,11 @@ utils::globalVariables(".GenericCallEnv", add = TRUE)
#' In some cases, however, the automatic cache hint inference is not
#' sufficient, and it is necessary to provide a cache hint. This is true
#' for `renderPrint()`. Unlike `renderText()`, it wraps the user-provided
#' expression in another function, before passing it to [markRenderFunction()]
#' expression in another function, before passing it to [createRenderFunction()]
#' (instead of [createRenderFunction()]). Because the user code is wrapped in
#' another function, `markRenderFunction()` is not able to automatically
#' another function, `createRenderFunction()` is not able to automatically
#' extract the user-provided code and use it in the cache key. Instead,
#' `renderPrint` calls `markRenderFunction()`, it explicitly passes along a
#' `renderPrint` calls `createRenderFunction()`, it explicitly passes along a
#' `cacheHint`, which includes a label and the original user expression.
#'
#' In general, if you need to provide a `cacheHint`, it is best practice to
Expand All @@ -310,19 +310,19 @@ utils::globalVariables(".GenericCallEnv", add = TRUE)
#'
#' ```
#' renderMyWidget <- function(expr) {
#' expr <- substitute(expr)
#' q <- rlang::enquo0(expr)
#'
#' htmlwidgets::shinyRenderWidget(expr,
#' htmlwidgets::shinyRenderWidget(
#' q,
#' myWidgetOutput,
#' quoted = TRUE,
#' env = parent.frame(),
#' cacheHint = list(label = "myWidget", userExpr = expr)
#' cacheHint = list(label = "myWidget", userQuo = q)
#' )
#' }
#' ```
#'
#' If your `render` function sets any internal state, you may find it useful
#' in your call to [createRenderFunction()] or [markRenderFunction()] to use
#' in your call to [createRenderFunction()] to use
#' the `cacheWriteHook` and/or `cacheReadHook` parameters. These hooks are
#' functions that run just before the object is stored in the cache, and just
#' after the object is retrieved from the cache. They can modify the data
Expand All @@ -339,8 +339,8 @@ utils::globalVariables(".GenericCallEnv", add = TRUE)
#' effects or modify some external state, and they must re-execute each time
#' in order to work properly.
#'
#' For developers of such code, they should call [createRenderFunction()] or
#' [markRenderFunction()] with `cacheHint = FALSE`.
#' For developers of such code, they should call [createRenderFunction()] (or
#' [markRenderFunction()]) with `cacheHint = FALSE`.
#'
#'
#' @section Caching with `renderPlot()`:
Expand Down
15 changes: 11 additions & 4 deletions R/deprecated.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,20 @@ deprecatedEnvQuotedMessage <- function() {
if (!in_devmode()) return(invisible())
if (is_false(getOption("shiny.deprecation.messages"))) return(invisible())

# manually
# Capture calling function
grandparent_call <- sys.call(-2)
# Turn language into user friendly string
grandparent_txt <- paste0(utils::capture.output({grandparent_call}), collapse = "\n")

msg <- paste0(
"The `env` and `quoted` arguments are deprecated as of shiny 1.6.0.",
"The `env` and `quoted` arguments are deprecated as of shiny 1.7.0.",
" Please use quosures from `rlang` instead.\n",
"See <https://github.com/rstudio/shiny/issues/3108> for more information."
"See <https://github.com/rstudio/shiny/issues/3108> for more information.\n",
"Function call:\n",
grandparent_txt
)
rlang::inform(message = msg, .frequency = "always", .frequency_id = msg, .file = stderr())
# Call less often as users do not have much control over this warning
rlang::inform(message = msg, .frequency = "regularly", .frequency_id = msg, .file = stderr())
}


Expand Down
2 changes: 1 addition & 1 deletion R/graph.R
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ MessageLogger = R6Class(
return(txt)
},
singleLine = function(txt) {
gsub("[^\\]\\n", "\\\\n", txt)
gsub("([^\\])\\n", "\\1\\\\n", txt)
},
valueStr = function(valueStr) {
paste0(
Expand Down
1 change: 0 additions & 1 deletion R/image-interact-opts.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#' `delay` milliseconds before sending an event.
#' @seealso [brushOpts()] for brushing events.
#' @export
#' @keywords internal
clickOpts <- function(id, clip = TRUE) {
if (is.null(id))
stop("id must not be NULL")
Expand Down
1 change: 1 addition & 0 deletions R/knitr.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#' themselves in knitr/rmarkdown documents.
#'
#' @name knitr_methods
#' @keywords internal
#' @param x Object to knit_print
#' @param ... Additional knit_print arguments
NULL
Expand Down
Loading

0 comments on commit 1b3ed88

Please sign in to comment.