Skip to content

Update utilities-tidy-eval.R and use as_label() #4076

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ S3method(widthDetails,titleGrob)
S3method(widthDetails,zeroGrob)
export("%+%")
export("%+replace%")
export(":=")
export(.data)
export(.pt)
export(.stroke)
Expand Down Expand Up @@ -271,7 +272,9 @@ export(annotation_logticks)
export(annotation_map)
export(annotation_raster)
export(arrow)
export(as_label)
export(as_labeller)
export(as_name)
export(autolayer)
export(autoplot)
export(benchplot)
Expand Down
4 changes: 2 additions & 2 deletions R/facet-.r
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ Facet <- ggproto("Facet", NULL,
#' # Let's enquote the named argument `var` to make it auto-quoting:
#' var <- enquo(var)
#'
#' # `quo_name()` will create a nice default name:
#' nm <- quo_name(var)
#' # `as_label()` will create a nice default name:
#' nm <- as_label(var)
#'
#' # Now let's unquote everything at the right place. Note that we also
#' # unquote `n` just in case the data frame has a column named
Expand Down
4 changes: 2 additions & 2 deletions R/quick-plot.r
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ qplot <- function(x, y, ..., data, facets = NULL, margins = FALSE,


if (is.null(xlab)) {
xlab <- quo_name(exprs$x)
xlab <- as_label(exprs$x)
}
if (is.null(ylab)) {
ylab <- quo_name(exprs$y)
ylab <- as_label(exprs$y)
}

if (missing(data)) {
Expand Down
34 changes: 26 additions & 8 deletions R/utilities-tidy-eval.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,22 @@
#' captured with [enquo()] or [enquos()]:
#' \code{expr(mean(!!enquo(arg), na.rm = TRUE))}.
#'
#' * \code{\link[rlang]{as_name}()} transforms a quoted variable name
#' into a string. Supplying something else than a quoted variable
#' name is an error.
#'
#' That's unlike \code{\link[rlang]{as_label}()} which also returns
#' a single string but supports any kind of R object as input,
#' including quoted function calls and vectors. Its purpose is to
#' summarise that object into a single label. That label is often
#' suitable as a default name.
#'
#' If you don't know what a quoted expression contains (for instance
#' expressions captured with \code{enquo()} could be a variable
#' name, a call to a function, or an unquoted constant), then use
#' \code{as_label()}. If you know you have quoted a simple variable
#' name, or would like to enforce this, use \code{as_name()}.
#'
#' To learn more about tidy eval and how to use these tools, visit
#' \url{https://tidyeval.tidyverse.org} and the
#' \href{https://adv-r.hadley.nz/metaprogramming.html}{Metaprogramming
Expand All @@ -25,12 +41,14 @@
#' @md
#' @name tidyeval
#' @keywords internal
#' @aliases quo quos enquo enquos quo_name
#' sym ensym syms ensyms
#' expr exprs enexpr enexprs
#' .data
#' @export quo quos enquo enquos quo_name
#' @export sym ensym syms ensyms
#' @export expr enexpr enexprs
#' @export .data
#' @aliases expr enquo enquos sym syms .data := as_name as_label
#' @export expr enquo enquos sym syms .data := as_name as_label
NULL

# For backward-compatibility, keep exporting the old ones

#' @name tidyeval
#' @keywords internal
#' @aliases quo_name quo quos enexpr enexprs ensym ensyms
#' @export quo_name quo quos enexpr enexprs ensym ensyms
NULL
33 changes: 25 additions & 8 deletions man/tidyeval.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/vars.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.