Closed
Description
I started getting an error when using glue
in ggplot as demonstrated below. The code runs successfully when the geom_hline()
layer is commented out:
library(dplyr)
library(glue)
library(ggplot2)
library(tidyr)
data <-
crossing(tier = factor(1:5),
x = 1:5) %>%
mutate(y = rnorm(n()))
data %>%
ggplot(aes(x, y)) +
geom_hline(yintercept = 0) +
geom_point() +
facet_wrap(~ glue('T{tier}'))
gives Error: ! Failed to evaluate glue component {tier}
.
The stack trace:
Backtrace:
▆
1. ├─base (local) `<fn>`(x)
2. ├─ggplot2:::print.ggplot(x)
3. │ ├─ggplot2::ggplot_build(x)
4. │ └─ggplot2:::ggplot_build.ggplot(x)
5. │ └─layout$setup(data, plot$data, plot$plot_env)
6. │ └─ggplot2 (local) setup(..., self = self)
7. │ └─self$facet$compute_layout(data, self$facet_params)
8. │ └─ggplot2 (local) compute_layout(..., self = self)
9. │ └─ggplot2::combine_vars(data, params$plot_env, vars, drop = params$drop)
10. │ ├─ggplot2:::compact(lapply(data, eval_facets, facets = vars, possible_columns = possible_columns))
11. │ │ └─base::vapply(x, is.null, logical(1))
12. │ └─base::lapply(data, eval_facets, facets = vars, possible_columns = possible_columns)
13. │ └─ggplot2 (local) FUN(X[[i]], ...)
14. │ ├─ggplot2:::compact(lapply(facets, eval_facet, data, possible_columns = possible_columns))
15. │ │ └─base::vapply(x, is.null, logical(1))
16. │ └─base::lapply(facets, eval_facet, data, possible_columns = possible_columns)
17. │ └─ggplot2 (local) FUN(X[[i]], ...)
18. │ ├─base::tryCatch(eval_tidy(facet, mask), ggplot2_missing_facet_var = function(e) NULL)
19. │ │ └─base (local) tryCatchList(expr, classes, parentenv, handlers)
20. │ │ └─base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]])
21. │ │ └─base (local) doTryCatch(return(expr), name, parentenv, handler)
22. │ └─rlang::eval_tidy(facet, mask)
23. ├─glue::glue("T{tier}")
24. │ └─glue::glue_data(...)
25. ├─glue (local) `<fn>`("tier")
26. │ ├─.transformer(expr, env) %||% .null
27. │ └─glue (local) .transformer(expr, env)
28. │ ├─glue:::with_glue_error(...)
29. │ │ └─base::withCallingHandlers(...)
30. │ └─base::eval(expr, envir)
31. │ └─base::eval(expr, envir)
32. └─ggplot2 (local) `<fn>`()