Skip to content

Commit 9209970

Browse files
Import rlang and use unqualified form for rlang functions (#3242)
* Import rlang and use unqualified form for rlang functions * Remove @importFrom(rlang, ...)
1 parent f79712f commit 9209970

22 files changed

+80
-97
lines changed

NAMESPACE

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -574,22 +574,9 @@ export(ylim)
574574
export(zeroGrob)
575575
import(grid)
576576
import(gtable)
577+
import(rlang)
577578
import(scales)
578579
importFrom(lazyeval,f_eval)
579-
importFrom(rlang,.data)
580-
importFrom(rlang,enexpr)
581-
importFrom(rlang,enexprs)
582-
importFrom(rlang,enquo)
583-
importFrom(rlang,enquos)
584-
importFrom(rlang,ensym)
585-
importFrom(rlang,ensyms)
586-
importFrom(rlang,expr)
587-
importFrom(rlang,exprs)
588-
importFrom(rlang,quo)
589-
importFrom(rlang,quo_name)
590-
importFrom(rlang,quos)
591-
importFrom(rlang,sym)
592-
importFrom(rlang,syms)
593580
importFrom(stats,setNames)
594581
importFrom(tibble,tibble)
595582
importFrom(utils,.DollarNames)

R/aes-calculated.r

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ make_labels <- function(mapping) {
9393
}
9494

9595
mapping <- strip_dots(mapping)
96-
if (rlang::is_quosure(mapping) && rlang::quo_is_symbol(mapping)) {
97-
name <- rlang::as_string(rlang::quo_get_expr(mapping))
96+
if (is_quosure(mapping) && quo_is_symbol(mapping)) {
97+
name <- as_string(quo_get_expr(mapping))
9898
} else {
99-
name <- rlang::quo_text(mapping)
99+
name <- quo_text(mapping)
100100
name <- gsub("\n.*$", "...", name)
101101
}
102102
name

R/aes.r

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,23 +75,23 @@ NULL
7575
#' cut3 <- function(x) cut_number(x, 3)
7676
#' scatter_by(mtcars, cut3(disp), drat)
7777
aes <- function(x, y, ...) {
78-
exprs <- rlang::enquos(x = x, y = y, ..., .ignore_empty = "all")
78+
exprs <- enquos(x = x, y = y, ..., .ignore_empty = "all")
7979
aes <- new_aes(exprs, env = parent.frame())
8080
rename_aes(aes)
8181
}
8282

8383
# Wrap symbolic objects in quosures but pull out constants out of
8484
# quosures for backward-compatibility
8585
new_aesthetic <- function(x, env = globalenv()) {
86-
if (rlang::is_quosure(x)) {
87-
if (!rlang::quo_is_symbolic(x)) {
88-
x <- rlang::quo_get_expr(x)
86+
if (is_quosure(x)) {
87+
if (!quo_is_symbolic(x)) {
88+
x <- quo_get_expr(x)
8989
}
9090
return(x)
9191
}
9292

93-
if (rlang::is_symbolic(x)) {
94-
x <- rlang::new_quosure(x, env = env)
93+
if (is_symbolic(x)) {
94+
x <- new_quosure(x, env = env)
9595
return(x)
9696
}
9797

@@ -110,7 +110,7 @@ print.uneval <- function(x, ...) {
110110
if (length(x) == 0) {
111111
cat("<empty>\n")
112112
} else {
113-
values <- vapply(x, rlang::quo_label, character(1))
113+
values <- vapply(x, quo_label, character(1))
114114
bullets <- paste0("* ", format(paste0("`", names(x), "`")), " -> ", values, "\n")
115115

116116
cat(bullets, sep = "")
@@ -240,7 +240,7 @@ aes_ <- function(x, y, ...) {
240240

241241
as_quosure_aes <- function(x) {
242242
if (is.formula(x) && length(x) == 2) {
243-
rlang::as_quosure(x)
243+
as_quosure(x)
244244
} else if (is.call(x) || is.name(x) || is.atomic(x)) {
245245
new_aesthetic(x, caller_env)
246246
} else {
@@ -262,7 +262,7 @@ aes_string <- function(x, y, ...) {
262262
caller_env <- parent.frame()
263263
mapping <- lapply(mapping, function(x) {
264264
if (is.character(x)) {
265-
x <- rlang::parse_expr(x)
265+
x <- parse_expr(x)
266266
}
267267
new_aesthetic(x, env = caller_env)
268268
})
@@ -289,7 +289,7 @@ aes_all <- function(vars) {
289289
# Quosure the symbols in the empty environment because they can only
290290
# refer to the data mask
291291
structure(
292-
lapply(vars, function(x) rlang::new_quosure(as.name(x), emptyenv())),
292+
lapply(vars, function(x) new_quosure(as.name(x), emptyenv())),
293293
class = "uneval"
294294
)
295295
}

R/axis-secondary.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ sec_axis <- function(trans = NULL, name = waiver(), breaks = waiver(), labels =
8383
# sec_axis() historically accpeted two-sided formula, so be permissive.
8484
if (length(trans) > 2) trans <- trans[c(1,3)]
8585

86-
trans <- rlang::as_function(trans)
86+
trans <- as_function(trans)
8787
ggproto(NULL, AxisSecondary,
8888
trans = trans,
8989
name = name,

R/bench.r

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
benchplot <- function(x) {
1616
x <- enquo(x)
17-
construct <- system.time(x <- rlang::eval_tidy(x))
17+
construct <- system.time(x <- eval_tidy(x))
1818
stopifnot(inherits(x, "ggplot"))
1919

2020
build <- system.time(data <- ggplot_build(x))

R/facet-.r

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ Facet <- ggproto("Facet", NULL,
225225
#' # Thanks to tidy eval idioms we now have another useful wrapper:
226226
#' p + wrap_cut(drat)
227227
vars <- function(...) {
228-
rlang::quos(...)
228+
quos(...)
229229
}
230230

231231

@@ -278,29 +278,29 @@ as_facets_list <- function(x) {
278278
if (inherits(x, "uneval")) {
279279
stop("Please use `vars()` to supply facet variables", call. = FALSE)
280280
}
281-
if (rlang::is_quosures(x)) {
282-
x <- rlang::quos_auto_name(x)
281+
if (is_quosures(x)) {
282+
x <- quos_auto_name(x)
283283
return(list(x))
284284
}
285285

286286
# This needs to happen early because we might get a formula.
287287
# facet_grid() directly converted strings to a formula while
288288
# facet_wrap() called as.quoted(). Hence this is a little more
289289
# complicated for backward compatibility.
290-
if (rlang::is_string(x)) {
291-
x <- rlang::parse_expr(x)
290+
if (is_string(x)) {
291+
x <- parse_expr(x)
292292
}
293293

294294
# At this level formulas are coerced to lists of lists for backward
295295
# compatibility with facet_grid(). The LHS and RHS are treated as
296296
# distinct facet dimensions and `+` defines multiple facet variables
297297
# inside each dimension.
298-
if (rlang::is_formula(x)) {
298+
if (is_formula(x)) {
299299
return(f_as_facets_list(x))
300300
}
301301

302302
# For backward-compatibility with facet_wrap()
303-
if (!rlang::is_bare_list(x)) {
303+
if (!is_bare_list(x)) {
304304
x <- as_quoted(x)
305305
}
306306

@@ -316,9 +316,9 @@ as_facets_list <- function(x) {
316316

317317
# Flatten a list of quosures objects to a quosures object, and compact it
318318
compact_facets <- function(x) {
319-
x <- rlang::flatten_if(x, rlang::is_list)
320-
null <- vapply(x, rlang::quo_is_null, logical(1))
321-
rlang::new_quosures(x[!null])
319+
x <- flatten_if(x, is_list)
320+
null <- vapply(x, quo_is_null, logical(1))
321+
new_quosures(x[!null])
322322
}
323323

324324
# Compatibility with plyr::as.quoted()
@@ -327,29 +327,29 @@ as_quoted <- function(x) {
327327
if (length(x) > 1) {
328328
x <- paste(x, collapse = "; ")
329329
}
330-
return(rlang::parse_exprs(x))
330+
return(parse_exprs(x))
331331
}
332332
if (is.null(x)) {
333333
return(list())
334334
}
335-
if (rlang::is_formula(x)) {
335+
if (is_formula(x)) {
336336
return(simplify(x))
337337
}
338338
list(x)
339339
}
340340
# From plyr:::as.quoted.formula
341341
simplify <- function(x) {
342-
if (length(x) == 2 && rlang::is_symbol(x[[1]], "~")) {
342+
if (length(x) == 2 && is_symbol(x[[1]], "~")) {
343343
return(simplify(x[[2]]))
344344
}
345345
if (length(x) < 3) {
346346
return(list(x))
347347
}
348348
op <- x[[1]]; a <- x[[2]]; b <- x[[3]]
349349

350-
if (rlang::is_symbol(op, c("+", "*", "~"))) {
350+
if (is_symbol(op, c("+", "*", "~"))) {
351351
c(simplify(a), simplify(b))
352-
} else if (rlang::is_symbol(op, "-")) {
352+
} else if (is_symbol(op, "-")) {
353353
c(simplify(a), expr(-!!simplify(b)))
354354
} else {
355355
list(x)
@@ -371,29 +371,29 @@ as_facets <- function(x) {
371371
return(x)
372372
}
373373

374-
if (rlang::is_formula(x)) {
374+
if (is_formula(x)) {
375375
# Use different formula method because plyr's does not handle the
376376
# environment correctly.
377377
f_as_facets(x)
378378
} else {
379379
vars <- as_quoted(x)
380-
rlang::as_quosures(vars, globalenv(), named = TRUE)
380+
as_quosures(vars, globalenv(), named = TRUE)
381381
}
382382
}
383383
f_as_facets <- function(f) {
384384
if (is.null(f)) {
385-
return(rlang::as_quosures(list()))
385+
return(as_quosures(list()))
386386
}
387387

388-
env <- rlang::f_env(f) %||% globalenv()
388+
env <- f_env(f) %||% globalenv()
389389

390390
# as.quoted() handles `+` specifications
391391
vars <- as.quoted(f)
392392

393393
# `.` in formulas is ignored
394394
vars <- discard_dots(vars)
395395

396-
rlang::as_quosures(vars, env, named = TRUE)
396+
as_quosures(vars, env, named = TRUE)
397397
}
398398
discard_dots <- function(x) {
399399
x[!vapply(x, identical, logical(1), as.name("."))]
@@ -406,7 +406,7 @@ is_facets <- function(x) {
406406
if (!length(x)) {
407407
return(FALSE)
408408
}
409-
all(vapply(x, rlang::is_quosure, logical(1)))
409+
all(vapply(x, is_quosure, logical(1)))
410410
}
411411

412412

@@ -422,8 +422,8 @@ eval_facets <- function(facets, data, env = globalenv()) {
422422
tibble::as_tibble(vars)
423423
}
424424
eval_facet <- function(facet, data, env = emptyenv()) {
425-
if (rlang::quo_is_symbol(facet)) {
426-
facet <- as.character(rlang::quo_get_expr(facet))
425+
if (quo_is_symbol(facet)) {
426+
facet <- as.character(quo_get_expr(facet))
427427

428428
if (facet %in% names(data)) {
429429
out <- data[[facet]]
@@ -433,7 +433,7 @@ eval_facet <- function(facet, data, env = emptyenv()) {
433433
return(out)
434434
}
435435

436-
rlang::eval_tidy(facet, data, env)
436+
eval_tidy(facet, data, env)
437437
}
438438

439439
layout_null <- function() {

R/facet-grid-.r

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ facet_grid <- function(rows = NULL, cols = NULL, scales = "fixed",
159159

160160
# Returns a list of quosures objects. The list has exactly two elements, `rows` and `cols`.
161161
grid_as_facets_list <- function(rows, cols) {
162-
is_rows_vars <- is.null(rows) || rlang::is_quosures(rows)
162+
is_rows_vars <- is.null(rows) || is_quosures(rows)
163163
if (!is_rows_vars) {
164164
if (!is.null(cols)) {
165165
stop("`rows` must be `NULL` or a `vars()` list if `cols` is a `vars()` list", call. = FALSE)
@@ -170,13 +170,13 @@ grid_as_facets_list <- function(rows, cols) {
170170
stop("A grid facet specification can't have more than two dimensions", call. = FALSE)
171171
}
172172
# Fill with empty quosures
173-
facets <- list(rows = rlang::quos(), cols = rlang::quos())
173+
facets <- list(rows = quos(), cols = quos())
174174
facets[seq_along(facets_list)] <- facets_list
175175
# Do not compact the legacy specs
176176
return(facets)
177177
}
178178

179-
is_cols_vars <- is.null(cols) || rlang::is_quosures(cols)
179+
is_cols_vars <- is.null(cols) || is_quosures(cols)
180180
if (!is_cols_vars) {
181181
stop("`cols` must be `NULL` or a `vars()` specification", call. = FALSE)
182182
}

R/geom-.r

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ Geom <- ggproto("Geom",
111111
# Fill in missing aesthetics with their defaults
112112
missing_aes <- setdiff(names(self$default_aes), names(data))
113113

114-
missing_eval <- lapply(self$default_aes[missing_aes], rlang::eval_tidy)
114+
missing_eval <- lapply(self$default_aes[missing_aes], eval_tidy)
115115
# Needed for geoms with defaults set to NULL (e.g. GeomSf)
116116
missing_eval <- compact(missing_eval)
117117

R/ggplot2.r

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#' @keywords internal
22
"_PACKAGE"
33

4-
#' @import scales grid gtable
4+
#' @import scales grid gtable rlang
55
#' @importFrom stats setNames
66
NULL

R/labels.r

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ update_labels <- function(p, labels) {
6666
#' # If you want to remove a label, set it to NULL.
6767
#' p + labs(title = "title") + labs(title = NULL)
6868
labs <- function(..., title = waiver(), subtitle = waiver(), caption = waiver(), tag = waiver()) {
69-
args <- rlang::list2(..., title = title, subtitle = subtitle, caption = caption, tag = tag)
69+
args <- list2(..., title = title, subtitle = subtitle, caption = caption, tag = tag)
7070

7171
is_waive <- vapply(args, is.waive, logical(1))
7272
args <- args[!is_waive]

R/layer.r

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ Layer <- ggproto("Layer", NULL,
226226
scales_add_defaults(plot$scales, data, aesthetics, plot$plot_env)
227227

228228
# Evaluate and check aesthetics
229-
evaled <- lapply(aesthetics, rlang::eval_tidy, data = data)
229+
evaled <- lapply(aesthetics, eval_tidy, data = data)
230230
evaled <- compact(evaled)
231231

232232
n <- nrow(data)
@@ -279,7 +279,7 @@ Layer <- ggproto("Layer", NULL,
279279
env <- new.env(parent = baseenv())
280280
env$stat <- stat
281281

282-
stat_data <- new_data_frame(lapply(new, rlang::eval_tidy, data, env))
282+
stat_data <- new_data_frame(lapply(new, eval_tidy, data, env))
283283
names(stat_data) <- names(new)
284284

285285
# Add any new scales, if needed

0 commit comments

Comments
 (0)