I'd like to extract values from a tbl_df object using a character string with a custom class but I'm getting the following error:
bar <- structure("x", class = c("foo", "character"))
tbl <- tibble::tibble(x = 1:3, y = letters[1:3])
tbl[[bar]]
#> Error in `tbl[[bar]]`:
#> ! Can't extract column with `bar`.
#> ✖ `bar` must be numeric or character, not a <foo/character> object.
Is there a work around for this that doesn't consist in removing the tbl_df/tbl classes of the tibble or rewriting accessor methods?
I'm developing a package that has functions generating objects with a custom class to perform input checks and work with some S3 methods. Some of these objects can be used to get data from a tibble. Currently, what I'm doing is removing the class of these object to extract the data and setting it back afterward but I don't like that.