r-lib / vctrs

Generic programming with typed R vectors
https://vctrs.r-lib.org
Other
282 stars 65 forks source link

Vectors in %in% Fails #1904

Open latot opened 6 months ago

latot commented 6 months ago

Hi, I'm pretty new using vctrs, still I was able to do some basics in a lib, I'm mainly following https://vctrs.r-lib.org/articles/s3-vector.html#equality-and-comparison

Rn, I found that we can't use %in%:

node <- function(x) {
  vctrs::new_vctr(x, class = "node")
}

data <- node(c(1, 2, 3))

data[[1]] %in% data
Error in `as.character()`:
! Can't convert `x` <node> to <character>.
Run `rlang::last_trace()` to see where the error occurred.

Is this the right way to do it? or is a bug?

Thx!

DavisVaughan commented 6 months ago

We should probably provide a definition for the new mtfrm() S3 generic if we can, used by match() and therefore %in%.

In the meantime you can use vctrs::vec_in() instead