Skip to content

Mapping facets with vec_slice() is too stringent #6292

Closed
@teunbrand

Description

@teunbrand

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions