Skip to content

Commit 73256c9

Browse files
Update utilities-tidy-eval.R and use as_label() (#4076)
Close #4063
1 parent 4ac00fe commit 73256c9

File tree

6 files changed

+60
-22
lines changed

6 files changed

+60
-22
lines changed

NAMESPACE

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ S3method(widthDetails,titleGrob)
143143
S3method(widthDetails,zeroGrob)
144144
export("%+%")
145145
export("%+replace%")
146+
export(":=")
146147
export(.data)
147148
export(.pt)
148149
export(.stroke)
@@ -271,7 +272,9 @@ export(annotation_logticks)
271272
export(annotation_map)
272273
export(annotation_raster)
273274
export(arrow)
275+
export(as_label)
274276
export(as_labeller)
277+
export(as_name)
275278
export(autolayer)
276279
export(autoplot)
277280
export(benchplot)

R/facet-.r

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@ Facet <- ggproto("Facet", NULL,
213213
#' # Let's enquote the named argument `var` to make it auto-quoting:
214214
#' var <- enquo(var)
215215
#'
216-
#' # `quo_name()` will create a nice default name:
217-
#' nm <- quo_name(var)
216+
#' # `as_label()` will create a nice default name:
217+
#' nm <- as_label(var)
218218
#'
219219
#' # Now let's unquote everything at the right place. Note that we also
220220
#' # unquote `n` just in case the data frame has a column named

R/quick-plot.r

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,10 @@ qplot <- function(x, y, ..., data, facets = NULL, margins = FALSE,
8989

9090

9191
if (is.null(xlab)) {
92-
xlab <- quo_name(exprs$x)
92+
xlab <- as_label(exprs$x)
9393
}
9494
if (is.null(ylab)) {
95-
ylab <- quo_name(exprs$y)
95+
ylab <- as_label(exprs$y)
9696
}
9797

9898
if (missing(data)) {

R/utilities-tidy-eval.R

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,22 @@
1717
#' captured with [enquo()] or [enquos()]:
1818
#' \code{expr(mean(!!enquo(arg), na.rm = TRUE))}.
1919
#'
20+
#' * \code{\link[rlang]{as_name}()} transforms a quoted variable name
21+
#' into a string. Supplying something else than a quoted variable
22+
#' name is an error.
23+
#'
24+
#' That's unlike \code{\link[rlang]{as_label}()} which also returns
25+
#' a single string but supports any kind of R object as input,
26+
#' including quoted function calls and vectors. Its purpose is to
27+
#' summarise that object into a single label. That label is often
28+
#' suitable as a default name.
29+
#'
30+
#' If you don't know what a quoted expression contains (for instance
31+
#' expressions captured with \code{enquo()} could be a variable
32+
#' name, a call to a function, or an unquoted constant), then use
33+
#' \code{as_label()}. If you know you have quoted a simple variable
34+
#' name, or would like to enforce this, use \code{as_name()}.
35+
#'
2036
#' To learn more about tidy eval and how to use these tools, visit
2137
#' \url{https://tidyeval.tidyverse.org} and the
2238
#' \href{https://adv-r.hadley.nz/metaprogramming.html}{Metaprogramming
@@ -25,12 +41,14 @@
2541
#' @md
2642
#' @name tidyeval
2743
#' @keywords internal
28-
#' @aliases quo quos enquo enquos quo_name
29-
#' sym ensym syms ensyms
30-
#' expr exprs enexpr enexprs
31-
#' .data
32-
#' @export quo quos enquo enquos quo_name
33-
#' @export sym ensym syms ensyms
34-
#' @export expr enexpr enexprs
35-
#' @export .data
44+
#' @aliases expr enquo enquos sym syms .data := as_name as_label
45+
#' @export expr enquo enquos sym syms .data := as_name as_label
46+
NULL
47+
48+
# For backward-compatibility, keep exporting the old ones
49+
50+
#' @name tidyeval
51+
#' @keywords internal
52+
#' @aliases quo_name quo quos enexpr enexprs ensym ensyms
53+
#' @export quo_name quo quos enexpr enexprs ensym ensyms
3654
NULL

man/tidyeval.Rd

Lines changed: 25 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/vars.Rd

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)