Skip to content

Commit cd9410c

Browse files
authored
Remove {glue} dependency (#5988)
* replace `glue::glue()` with `paste0()` * remove glue imports * accept snapshot * add news bullet
1 parent c6a9a14 commit cd9410c

File tree

8 files changed

+29
-36
lines changed

8 files changed

+29
-36
lines changed

DESCRIPTION

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ Depends:
3333
R (>= 3.5)
3434
Imports:
3535
cli,
36-
glue,
3736
grDevices,
3837
grid,
3938
gtable (>= 0.1.1),

NAMESPACE

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -727,8 +727,6 @@ import(gtable)
727727
import(rlang)
728728
import(scales)
729729
import(vctrs)
730-
importFrom(glue,glue)
731-
importFrom(glue,glue_collapse)
732730
importFrom(grid,arrow)
733731
importFrom(grid,unit)
734732
importFrom(lifecycle,deprecated)

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# ggplot2 (development version)
22

3+
* ggplot2 no longer imports {glue} (@teunbrand, #5986).
34
* `geom_rect()` can now derive the required corners positions from `x`/`width`
45
or `y`/`height` parameterisation (@teunbrand, #5861).
56
* All position scales now use the same definition of `x` and `y` aesthetics.

R/aes-evaluation.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,9 +231,9 @@ is_calculated <- function(x, warn = FALSE) {
231231
} else if (is.symbol(x)) {
232232
res <- is_dotted_var(as.character(x))
233233
if (res && warn) {
234-
what <- I(glue("The dot-dot notation (`{x}`)"))
234+
what <- I(paste0("The dot-dot notation (`", x, "`)"))
235235
var <- gsub(match_calculated_aes, "\\1", as.character(x))
236-
with <- I(glue("`after_stat({var})`"))
236+
with <- I(paste0("`after_stat(", var, ")`"))
237237
deprecate_warn0("3.4.0", what, with, id = "ggplot-warn-aes-dot-dot")
238238
}
239239
res
@@ -242,9 +242,9 @@ is_calculated <- function(x, warn = FALSE) {
242242
} else if (is.call(x)) {
243243
if (identical(x[[1]], quote(stat))) {
244244
if (warn) {
245-
what <- I(glue("`{expr_deparse(x)}`"))
245+
what <- I(paste0("`", expr_deparse(x), "`"))
246246
x[[1]] <- quote(after_stat)
247-
with <- I(glue("`{expr_deparse(x)}`"))
247+
with <- I(paste0("`", expr_deparse(x), "`"))
248248
deprecate_warn0("3.4.0", what, with, id = "ggplot-warn-aes-stat")
249249
}
250250
TRUE

R/fortify.R

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,21 +74,21 @@ validate_as_data_frame <- function(data) {
7474

7575
#' @export
7676
fortify.default <- function(model, data, ...) {
77-
msg0 <- paste0(
78-
"{{.arg data}} must be a {{.cls data.frame}}, ",
79-
"or an object coercible by {{.fn fortify}}, or a valid ",
80-
"{{.cls data.frame}}-like object coercible by {{.fn as.data.frame}}"
77+
msg <- paste0(
78+
"{.arg data} must be a {.cls data.frame}, ",
79+
"or an object coercible by {.fn fortify}, or a valid ",
80+
"{.cls data.frame}-like object coercible by {.fn as.data.frame}"
8181
)
8282
if (inherits(model, "uneval")) {
8383
msg <- c(
84-
glue(msg0, ", not {obj_type_friendly(model)}."),
84+
paste0(msg, ", not ", obj_type_friendly(model), "."),
8585
"i" = "Did you accidentally pass {.fn aes} to the {.arg data} argument?"
8686
)
8787
cli::cli_abort(msg)
8888
}
89-
msg0 <- paste0(msg0, ". ")
89+
msg <- paste0(msg, ".")
9090
try_fetch(
9191
validate_as_data_frame(model),
92-
error = function(cnd) cli::cli_abort(glue(msg0), parent = cnd)
92+
error = function(cnd) cli::cli_abort(msg, parent = cnd)
9393
)
9494
}

R/ggplot2-package.R

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
## usethis namespace: start
55
#' @import scales grid gtable rlang vctrs
6-
#' @importFrom glue glue glue_collapse
76
#' @importFrom lifecycle deprecated
87
#' @importFrom stats setNames
98
#' @importFrom utils head tail

R/labels.R

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -205,40 +205,36 @@ get_alt_text.gtable <- function(p, ...) {
205205
generate_alt_text <- function(p) {
206206
# Combine titles
207207
if (!is.null(p$label$title %||% p$labels$subtitle)) {
208-
title <- glue(glue_collapse(
209-
sub("\\.?$", "", c(p$labels$title, p$labels$subtitle)),
210-
last = ": "
211-
), ". ")
208+
title <- sub("\\.?$", "", c(p$labels$title, p$labels$subtitle))
209+
if (length(title) == 2) {
210+
title <- paste0(title[1], ": ", title[2])
211+
}
212+
title <- paste0(title, ". ")
212213
title <- safe_string(title)
213214
} else {
214215
title <- ""
215216
}
216217

217218

218219
# Get axes descriptions
219-
axes <- glue(" showing ", glue_collapse(
220-
c(scale_description(p, "x"), scale_description(p, "y")),
221-
last = " and "
222-
))
220+
axes <- paste0(" showing ", scale_description(p, "x"), " and ", scale_description(p, "y"))
223221
axes <- safe_string(axes)
224222

225223
# Get layer types
226224
layers <- vapply(p$layers, function(l) snake_class(l$geom), character(1))
227225
layers <- sub("_", " ", sub("^geom_", "", unique0(layers)))
228-
layers <- glue(
229-
" using ",
230-
if (length(layers) == 1) "a " else "",
231-
glue_collapse(layers, sep = ", ", last = " and "),
232-
" layer",
233-
if (length(layers) == 1) "" else "s"
234-
)
226+
if (length(layers) == 1) {
227+
layers <- paste0(" using a ", layers, " layer")
228+
} else {
229+
layers <- paste0(" using ", oxford_comma(layers), " layers")
230+
}
235231
layers <- safe_string(layers)
236232

237233
# Combine
238-
alt <- glue_collapse(
239-
c(glue("{title}A plot{axes}{layers}"), p$labels$alt_insight),
240-
last = ". "
241-
)
234+
alt <- paste0(title, "A plot", axes, layers, ".")
235+
if (!is.null(p$labels$alt_insight)) {
236+
alt <- paste0(alt, " ", p$labels$alt_insight)
237+
}
242238
as.character(alt)
243239
}
244240
safe_string <- function(string) {
@@ -258,5 +254,5 @@ scale_description <- function(p, name) {
258254
if (is.null(lab)) {
259255
return(NULL)
260256
}
261-
glue("{lab} on {type} {name}-axis")
257+
paste0(lab, " on ", type, " ", name, "-axis")
262258
}

tests/testthat/_snaps/labels.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Code
44
get_alt_text(p)
55
Output
6-
[1] "A plot showing class on the x-axis and count on the y-axis using a bar layer"
6+
[1] "A plot showing class on the x-axis and count on the y-axis using a bar layer."
77

88
# plot.tag.position rejects invalid input
99

0 commit comments

Comments
 (0)