diff --git a/DESCRIPTION b/DESCRIPTION index dcaf992c7f..3f34454b36 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -33,7 +33,6 @@ Depends: R (>= 3.5) Imports: cli, - glue, grDevices, grid, gtable (>= 0.1.1), diff --git a/NAMESPACE b/NAMESPACE index 9068973de0..d6093fe7e9 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -727,8 +727,6 @@ import(gtable) import(rlang) import(scales) import(vctrs) -importFrom(glue,glue) -importFrom(glue,glue_collapse) importFrom(grid,arrow) importFrom(grid,unit) importFrom(lifecycle,deprecated) diff --git a/NEWS.md b/NEWS.md index ce5f733099..381ba4c097 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,6 @@ # ggplot2 (development version) +* ggplot2 no longer imports {glue} (@teunbrand, #5986). * `geom_rect()` can now derive the required corners positions from `x`/`width` or `y`/`height` parameterisation (@teunbrand, #5861). * All position scales now use the same definition of `x` and `y` aesthetics. diff --git a/R/aes-evaluation.R b/R/aes-evaluation.R index e128fd2c15..4c682e3f63 100644 --- a/R/aes-evaluation.R +++ b/R/aes-evaluation.R @@ -231,9 +231,9 @@ is_calculated <- function(x, warn = FALSE) { } else if (is.symbol(x)) { res <- is_dotted_var(as.character(x)) if (res && warn) { - what <- I(glue("The dot-dot notation (`{x}`)")) + what <- I(paste0("The dot-dot notation (`", x, "`)")) var <- gsub(match_calculated_aes, "\\1", as.character(x)) - with <- I(glue("`after_stat({var})`")) + with <- I(paste0("`after_stat(", var, ")`")) deprecate_warn0("3.4.0", what, with, id = "ggplot-warn-aes-dot-dot") } res @@ -242,9 +242,9 @@ is_calculated <- function(x, warn = FALSE) { } else if (is.call(x)) { if (identical(x[[1]], quote(stat))) { if (warn) { - what <- I(glue("`{expr_deparse(x)}`")) + what <- I(paste0("`", expr_deparse(x), "`")) x[[1]] <- quote(after_stat) - with <- I(glue("`{expr_deparse(x)}`")) + with <- I(paste0("`", expr_deparse(x), "`")) deprecate_warn0("3.4.0", what, with, id = "ggplot-warn-aes-stat") } TRUE diff --git a/R/fortify.R b/R/fortify.R index 0e0b67516d..3a61e3ce49 100644 --- a/R/fortify.R +++ b/R/fortify.R @@ -74,21 +74,21 @@ validate_as_data_frame <- function(data) { #' @export fortify.default <- function(model, data, ...) { - msg0 <- paste0( - "{{.arg data}} must be a {{.cls data.frame}}, ", - "or an object coercible by {{.fn fortify}}, or a valid ", - "{{.cls data.frame}}-like object coercible by {{.fn as.data.frame}}" + msg <- paste0( + "{.arg data} must be a {.cls data.frame}, ", + "or an object coercible by {.fn fortify}, or a valid ", + "{.cls data.frame}-like object coercible by {.fn as.data.frame}" ) if (inherits(model, "uneval")) { msg <- c( - glue(msg0, ", not {obj_type_friendly(model)}."), + paste0(msg, ", not ", obj_type_friendly(model), "."), "i" = "Did you accidentally pass {.fn aes} to the {.arg data} argument?" ) cli::cli_abort(msg) } - msg0 <- paste0(msg0, ". ") + msg <- paste0(msg, ".") try_fetch( validate_as_data_frame(model), - error = function(cnd) cli::cli_abort(glue(msg0), parent = cnd) + error = function(cnd) cli::cli_abort(msg, parent = cnd) ) } diff --git a/R/ggplot2-package.R b/R/ggplot2-package.R index 539f03db97..46c1b334f0 100644 --- a/R/ggplot2-package.R +++ b/R/ggplot2-package.R @@ -3,7 +3,6 @@ ## usethis namespace: start #' @import scales grid gtable rlang vctrs -#' @importFrom glue glue glue_collapse #' @importFrom lifecycle deprecated #' @importFrom stats setNames #' @importFrom utils head tail diff --git a/R/labels.R b/R/labels.R index 66401683cb..d617bd9238 100644 --- a/R/labels.R +++ b/R/labels.R @@ -205,10 +205,11 @@ get_alt_text.gtable <- function(p, ...) { generate_alt_text <- function(p) { # Combine titles if (!is.null(p$label$title %||% p$labels$subtitle)) { - title <- glue(glue_collapse( - sub("\\.?$", "", c(p$labels$title, p$labels$subtitle)), - last = ": " - ), ". ") + title <- sub("\\.?$", "", c(p$labels$title, p$labels$subtitle)) + if (length(title) == 2) { + title <- paste0(title[1], ": ", title[2]) + } + title <- paste0(title, ". ") title <- safe_string(title) } else { title <- "" @@ -216,29 +217,24 @@ generate_alt_text <- function(p) { # Get axes descriptions - axes <- glue(" showing ", glue_collapse( - c(scale_description(p, "x"), scale_description(p, "y")), - last = " and " - )) + axes <- paste0(" showing ", scale_description(p, "x"), " and ", scale_description(p, "y")) axes <- safe_string(axes) # Get layer types layers <- vapply(p$layers, function(l) snake_class(l$geom), character(1)) layers <- sub("_", " ", sub("^geom_", "", unique0(layers))) - layers <- glue( - " using ", - if (length(layers) == 1) "a " else "", - glue_collapse(layers, sep = ", ", last = " and "), - " layer", - if (length(layers) == 1) "" else "s" - ) + if (length(layers) == 1) { + layers <- paste0(" using a ", layers, " layer") + } else { + layers <- paste0(" using ", oxford_comma(layers), " layers") + } layers <- safe_string(layers) # Combine - alt <- glue_collapse( - c(glue("{title}A plot{axes}{layers}"), p$labels$alt_insight), - last = ". " - ) + alt <- paste0(title, "A plot", axes, layers, ".") + if (!is.null(p$labels$alt_insight)) { + alt <- paste0(alt, " ", p$labels$alt_insight) + } as.character(alt) } safe_string <- function(string) { @@ -258,5 +254,5 @@ scale_description <- function(p, name) { if (is.null(lab)) { return(NULL) } - glue("{lab} on {type} {name}-axis") + paste0(lab, " on ", type, " ", name, "-axis") } diff --git a/tests/testthat/_snaps/labels.md b/tests/testthat/_snaps/labels.md index 8c673cfe11..87b2cb4fe2 100644 --- a/tests/testthat/_snaps/labels.md +++ b/tests/testthat/_snaps/labels.md @@ -3,7 +3,7 @@ Code get_alt_text(p) Output - [1] "A plot showing class on the x-axis and count on the y-axis using a bar layer" + [1] "A plot showing class on the x-axis and count on the y-axis using a bar layer." # plot.tag.position rejects invalid input