Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Error: ! Failed to evaluate glue component #5670

Closed
sirallen opened this issue Jan 30, 2024 · 6 comments · Fixed by #5671
Closed

Error: ! Failed to evaluate glue component #5670

sirallen opened this issue Jan 30, 2024 · 6 comments · Fixed by #5671
Labels
bug an unexpected problem or unintended behavior facets 💎

Comments

@sirallen
Copy link

sirallen commented Jan 30, 2024

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>`()
@teunbrand
Copy link
Collaborator

Thanks for the report! Did this code used to work (also with geom_hline()) and no longer does?

@sirallen
Copy link
Author

Yes, it worked previously -- I auto-updated some packages (not sure which ones) and now it no longer works.

@teunbrand
Copy link
Collaborator

Thanks that is helpful to know. I can reproduce this on my end, but can I ask you about the versions of R, ggplot2, scales and glue you're using anyway?

@sirallen
Copy link
Author

R version 4.3.2 (2023-10-31)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS Big Sur 11.4

... 

other attached packages:
[1] ... glue_1.7.0    ggplot2_3.4.4 ...

loaded via a namespace (and not attached):
 [1]  ... scales_1.3.0    ...

@teunbrand
Copy link
Collaborator

I've tested a little bit and it all seems to work fine with glue 1.6.2 but not 1.7.0.

I think the issue is as follows. ggplot2 throws a special error when facetting columns are absent, like for the geom_hline() case. This error is then caught and is given special treatment (i.e. it applies to all facets). However, glue now wraps errors (see tidyverse/glue#294) that hide the special ggplot2 error. The special error is still there, but it doesn't get caught as such.

@sirallen
Copy link
Author

@teunbrand Thank you for investigating!

@teunbrand teunbrand added bug an unexpected problem or unintended behavior facets 💎 labels Feb 2, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug an unexpected problem or unintended behavior facets 💎
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants