Skip to content

Commit

Permalink
Remove {glue} dependency (#5988)
Browse files Browse the repository at this point in the history
* replace `glue::glue()` with `paste0()`

* remove glue imports

* accept snapshot

* add news bullet
  • Loading branch information
teunbrand authored Jul 10, 2024
1 parent c6a9a14 commit cd9410c
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 36 deletions.
1 change: 0 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ Depends:
R (>= 3.5)
Imports:
cli,
glue,
grDevices,
grid,
gtable (>= 0.1.1),
Expand Down
2 changes: 0 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
8 changes: 4 additions & 4 deletions R/aes-evaluation.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
14 changes: 7 additions & 7 deletions R/fortify.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
}
1 change: 0 additions & 1 deletion R/ggplot2-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 16 additions & 20 deletions R/labels.R
Original file line number Diff line number Diff line change
Expand Up @@ -205,40 +205,36 @@ 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 <- ""
}


# 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) {
Expand All @@ -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")
}
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/labels.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit cd9410c

Please sign in to comment.