I have an S4 class that inherits from data.frame:
> setClass("Foo", contains="data.frame")
> x <- new("Foo", data.frame(a=1:2))
Now dplyr::filter works but issues a warning:
> x %>% dplyr::filter(a > 1)
a
1 2
Warning message:
In class(x) <- c("tbl_df", "tbl", "data.frame") :
Setting class(x) to multiple strings ("tbl_df", "tbl", ...); result
will no longer be an S4 object
Is there any good way to get rid of this warning? I can create a new
generic of filter, and wrap the dplyr version in this something
like
dplyr::filter(as.data.frame(unclass(x)), ...)
but isn't the point with inheritance to avoid such extra work?
Is this warning related to dplyr not being aware of S4 objects?
Edit: same behavior for dplyr 0.4.3 and 0.5.0
dplyr utilises the tibble package, where a conversion from a data.frame to a tibble takes place which assigns three classes to the argument. unclass() is called before this, but unclass'ing does not strip the object of its status as being an S4 object, and so the warning above occurs.
In short, this is a problem within dplyr. I think you would have to make wrappers for the generics.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With