Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Mapping facets with vec_slice() is too stringent #6292

Open
teunbrand opened this issue Jan 22, 2025 · 1 comment · May be fixed by #6297
Open

Mapping facets with vec_slice() is too stringent #6292

teunbrand opened this issue Jan 22, 2025 · 1 comment · May be fixed by #6297

Comments

@teunbrand
Copy link
Collaborator

This problem was identified in #6287 and affects 3 packages.

Essentially, when you're dealing with a data.frame superclass (rather than a subclass), vec_slice() complains.

vctrs::vec_slice(mtcars, 1)
#>           mpg cyl disp  hp drat   wt  qsec vs am gear carb
#> Mazda RX4  21   6  160 110  3.9 2.62 16.46  0  1    4    4

df <- mtcars
class(df) <- union(class(df), "foo")

vctrs::vec_slice(df, 1)
#> Error in `vctrs::vec_slice()`:
#> ! `x` must be a vector, not a <data.frame/foo> object.

Created on 2025-01-22 with reprex v2.1.1

This normally doesn't happen because we rebuild our own plain data.frame after evaluating aesthetics, but it becomes a problem before that when mapping facets:

data <- vec_slice(data, facet_vals$.index)

@teunbrand
Copy link
Collaborator Author

More realistic reprex:

devtools::load_all("~/packages/ggplot2/")
#> ℹ Loading ggplot2

df <- mpg
class(df) <- union(class(df), "foo")

ggplot(df, aes(displ, hwy)) +
  geom_point() +
  facet_grid(~ year)
#> Error in `vec_slice()` at ggplot2/R/facet-grid-.R:312:7:
#> ! `x` must be a vector, not a <tbl_df/tbl/data.frame/foo> object.

Created on 2025-01-22 with reprex v2.1.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant