Skip to content

Import rlang and use unqualified form for rlang functions #3242

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
15 changes: 1 addition & 14 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -574,22 +574,9 @@ export(ylim)
export(zeroGrob)
import(grid)
import(gtable)
import(rlang)
import(scales)
importFrom(lazyeval,f_eval)
importFrom(rlang,.data)
importFrom(rlang,enexpr)
importFrom(rlang,enexprs)
importFrom(rlang,enquo)
importFrom(rlang,enquos)
importFrom(rlang,ensym)
importFrom(rlang,ensyms)
importFrom(rlang,expr)
importFrom(rlang,exprs)
importFrom(rlang,quo)
importFrom(rlang,quo_name)
importFrom(rlang,quos)
importFrom(rlang,sym)
importFrom(rlang,syms)
importFrom(stats,setNames)
importFrom(tibble,tibble)
importFrom(utils,.DollarNames)
6 changes: 3 additions & 3 deletions R/aes-calculated.r
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ make_labels <- function(mapping) {
}

mapping <- strip_dots(mapping)
if (rlang::is_quosure(mapping) && rlang::quo_is_symbol(mapping)) {
name <- rlang::as_string(rlang::quo_get_expr(mapping))
if (is_quosure(mapping) && quo_is_symbol(mapping)) {
name <- as_string(quo_get_expr(mapping))
} else {
name <- rlang::quo_text(mapping)
name <- quo_text(mapping)
name <- gsub("\n.*$", "...", name)
}
name
Expand Down
20 changes: 10 additions & 10 deletions R/aes.r
Original file line number Diff line number Diff line change
Expand Up @@ -75,23 +75,23 @@ NULL
#' cut3 <- function(x) cut_number(x, 3)
#' scatter_by(mtcars, cut3(disp), drat)
aes <- function(x, y, ...) {
exprs <- rlang::enquos(x = x, y = y, ..., .ignore_empty = "all")
exprs <- enquos(x = x, y = y, ..., .ignore_empty = "all")
aes <- new_aes(exprs, env = parent.frame())
rename_aes(aes)
}

# Wrap symbolic objects in quosures but pull out constants out of
# quosures for backward-compatibility
new_aesthetic <- function(x, env = globalenv()) {
if (rlang::is_quosure(x)) {
if (!rlang::quo_is_symbolic(x)) {
x <- rlang::quo_get_expr(x)
if (is_quosure(x)) {
if (!quo_is_symbolic(x)) {
x <- quo_get_expr(x)
}
return(x)
}

if (rlang::is_symbolic(x)) {
x <- rlang::new_quosure(x, env = env)
if (is_symbolic(x)) {
x <- new_quosure(x, env = env)
return(x)
}

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

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

as_quosure_aes <- function(x) {
if (is.formula(x) && length(x) == 2) {
rlang::as_quosure(x)
as_quosure(x)
} else if (is.call(x) || is.name(x) || is.atomic(x)) {
new_aesthetic(x, caller_env)
} else {
Expand All @@ -262,7 +262,7 @@ aes_string <- function(x, y, ...) {
caller_env <- parent.frame()
mapping <- lapply(mapping, function(x) {
if (is.character(x)) {
x <- rlang::parse_expr(x)
x <- parse_expr(x)
}
new_aesthetic(x, env = caller_env)
})
Expand All @@ -289,7 +289,7 @@ aes_all <- function(vars) {
# Quosure the symbols in the empty environment because they can only
# refer to the data mask
structure(
lapply(vars, function(x) rlang::new_quosure(as.name(x), emptyenv())),
lapply(vars, function(x) new_quosure(as.name(x), emptyenv())),
class = "uneval"
)
}
Expand Down
2 changes: 1 addition & 1 deletion R/axis-secondary.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ sec_axis <- function(trans = NULL, name = waiver(), breaks = waiver(), labels =
# sec_axis() historically accpeted two-sided formula, so be permissive.
if (length(trans) > 2) trans <- trans[c(1,3)]

trans <- rlang::as_function(trans)
trans <- as_function(trans)
ggproto(NULL, AxisSecondary,
trans = trans,
name = name,
Expand Down
2 changes: 1 addition & 1 deletion R/bench.r
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

benchplot <- function(x) {
x <- enquo(x)
construct <- system.time(x <- rlang::eval_tidy(x))
construct <- system.time(x <- eval_tidy(x))
stopifnot(inherits(x, "ggplot"))

build <- system.time(data <- ggplot_build(x))
Expand Down
48 changes: 24 additions & 24 deletions R/facet-.r
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ Facet <- ggproto("Facet", NULL,
#' # Thanks to tidy eval idioms we now have another useful wrapper:
#' p + wrap_cut(drat)
vars <- function(...) {
rlang::quos(...)
quos(...)
}


Expand Down Expand Up @@ -278,29 +278,29 @@ as_facets_list <- function(x) {
if (inherits(x, "uneval")) {
stop("Please use `vars()` to supply facet variables", call. = FALSE)
}
if (rlang::is_quosures(x)) {
x <- rlang::quos_auto_name(x)
if (is_quosures(x)) {
x <- quos_auto_name(x)
return(list(x))
}

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

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

# For backward-compatibility with facet_wrap()
if (!rlang::is_bare_list(x)) {
if (!is_bare_list(x)) {
x <- as_quoted(x)
}

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

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

# Compatibility with plyr::as.quoted()
Expand All @@ -327,29 +327,29 @@ as_quoted <- function(x) {
if (length(x) > 1) {
x <- paste(x, collapse = "; ")
}
return(rlang::parse_exprs(x))
return(parse_exprs(x))
}
if (is.null(x)) {
return(list())
}
if (rlang::is_formula(x)) {
if (is_formula(x)) {
return(simplify(x))
}
list(x)
}
# From plyr:::as.quoted.formula
simplify <- function(x) {
if (length(x) == 2 && rlang::is_symbol(x[[1]], "~")) {
if (length(x) == 2 && is_symbol(x[[1]], "~")) {
return(simplify(x[[2]]))
}
if (length(x) < 3) {
return(list(x))
}
op <- x[[1]]; a <- x[[2]]; b <- x[[3]]

if (rlang::is_symbol(op, c("+", "*", "~"))) {
if (is_symbol(op, c("+", "*", "~"))) {
c(simplify(a), simplify(b))
} else if (rlang::is_symbol(op, "-")) {
} else if (is_symbol(op, "-")) {
c(simplify(a), expr(-!!simplify(b)))
} else {
list(x)
Expand All @@ -371,29 +371,29 @@ as_facets <- function(x) {
return(x)
}

if (rlang::is_formula(x)) {
if (is_formula(x)) {
# Use different formula method because plyr's does not handle the
# environment correctly.
f_as_facets(x)
} else {
vars <- as_quoted(x)
rlang::as_quosures(vars, globalenv(), named = TRUE)
as_quosures(vars, globalenv(), named = TRUE)
}
}
f_as_facets <- function(f) {
if (is.null(f)) {
return(rlang::as_quosures(list()))
return(as_quosures(list()))
}

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

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

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

rlang::as_quosures(vars, env, named = TRUE)
as_quosures(vars, env, named = TRUE)
}
discard_dots <- function(x) {
x[!vapply(x, identical, logical(1), as.name("."))]
Expand All @@ -406,7 +406,7 @@ is_facets <- function(x) {
if (!length(x)) {
return(FALSE)
}
all(vapply(x, rlang::is_quosure, logical(1)))
all(vapply(x, is_quosure, logical(1)))
}


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

if (facet %in% names(data)) {
out <- data[[facet]]
Expand All @@ -433,7 +433,7 @@ eval_facet <- function(facet, data, env = emptyenv()) {
return(out)
}

rlang::eval_tidy(facet, data, env)
eval_tidy(facet, data, env)
}

layout_null <- function() {
Expand Down
6 changes: 3 additions & 3 deletions R/facet-grid-.r
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ facet_grid <- function(rows = NULL, cols = NULL, scales = "fixed",

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

is_cols_vars <- is.null(cols) || rlang::is_quosures(cols)
is_cols_vars <- is.null(cols) || is_quosures(cols)
if (!is_cols_vars) {
stop("`cols` must be `NULL` or a `vars()` specification", call. = FALSE)
}
Expand Down
2 changes: 1 addition & 1 deletion R/geom-.r
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ Geom <- ggproto("Geom",
# Fill in missing aesthetics with their defaults
missing_aes <- setdiff(names(self$default_aes), names(data))

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

Expand Down
2 changes: 1 addition & 1 deletion R/ggplot2.r
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' @keywords internal
"_PACKAGE"

#' @import scales grid gtable
#' @import scales grid gtable rlang
#' @importFrom stats setNames
NULL
2 changes: 1 addition & 1 deletion R/labels.r
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ update_labels <- function(p, labels) {
#' # If you want to remove a label, set it to NULL.
#' p + labs(title = "title") + labs(title = NULL)
labs <- function(..., title = waiver(), subtitle = waiver(), caption = waiver(), tag = waiver()) {
args <- rlang::list2(..., title = title, subtitle = subtitle, caption = caption, tag = tag)
args <- list2(..., title = title, subtitle = subtitle, caption = caption, tag = tag)

is_waive <- vapply(args, is.waive, logical(1))
args <- args[!is_waive]
Expand Down
4 changes: 2 additions & 2 deletions R/layer.r
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ Layer <- ggproto("Layer", NULL,
scales_add_defaults(plot$scales, data, aesthetics, plot$plot_env)

# Evaluate and check aesthetics
evaled <- lapply(aesthetics, rlang::eval_tidy, data = data)
evaled <- lapply(aesthetics, eval_tidy, data = data)
evaled <- compact(evaled)

n <- nrow(data)
Expand Down Expand Up @@ -279,7 +279,7 @@ Layer <- ggproto("Layer", NULL,
env <- new.env(parent = baseenv())
env$stat <- stat

stat_data <- new_data_frame(lapply(new, rlang::eval_tidy, data, env))
stat_data <- new_data_frame(lapply(new, eval_tidy, data, env))
names(stat_data) <- names(new)

# Add any new scales, if needed
Expand Down
Loading