[Bioc-devel] Compatibility of Bioconductor with tidyverse S3 classes/methods

Michael Lawrence |@wrence@m|ch@e| @end|ng |rom gene@com
Fri Feb 7 01:01:25 CET 2020


Martin's comments are great.

I'll just give some technical help. The "tbl_df" S4 class is already
defined by dplyr (and more properly), so omit the call to
setOldClass(). Then, things work a bit better.

> my %>% nest(-b) # had to fix this from your example
[some ugly result]
Warning messages:
1: In class(x) <- c(subclass, tibble_class) :
  Setting class(x) to multiple strings ("tbl_df", "tbl", ...); result
will no longer be an S4 object
2: In split.default(data[nest_vars], idx) :
  data length is not a multiple of split variable

I would argue that this is an issue with the tidyverse. They provide
an S4 class, which should in principle work, because S4 is compatible
enough with S3, but the use of class<-() breaks it. There may be a way
to make class()<- work in such cases. I will think about it.

The right way to do it with S4 would be to just call initialize(x,
...) in new_tibble(). They have to implement the initialize() logic
themselves using update_tibble_attrs(). S4 gives you that for free.

And there are more issues but I think this is a good example of the
difficulties.

Michael

On Thu, Feb 6, 2020 at 2:46 PM stefano <mangiolastefano using gmail.com> wrote:
>
> Hello,
>
> I have a package (ttBulk) under review. I have been told to replace the S3
> system to S4. My package is based on the class tbl_df and must be fully
> compatible with tidyverse methods (inheritance). After some tests and
> research I understood that tidyverse ecosystem is not compatible with S4
> classes.
>
>  For example, several methos do not apparently handle S4 objects based on
> S3 tbl_df
>
> ```library(tidyverse)setOldClass("tbl_df")
> setClass("test2", contains = "tbl_df")
> my <- new("test2",  tibble(a = 1))
> my %>%  mutate(b = 3)
>
>    a b
> 1 1 3
> ```
>
>  ```my <- new("test2",  tibble(a = rnorm(100), b = 1))
> my %>% nest(data = -b)
> Error: `x` must be a vector, not a `test2` object
> Run `rlang::last_error()` to see where the error occurred.
> ```
>
> Could you please advise whether a tidyverse based package can be hosted on
> Bioconductor, and if S4 classes are really mandatory? I need to understand
> if I am forced to submit to CRAN instead (although Bioconductor would be a
> good fit, sice I try to interface transcriptional analysis tools to tidy
> universe)
>
>
> Thanks a lot.
> Stefano
>
>         [[alternative HTML version deleted]]
>
> _______________________________________________
> Bioc-devel using r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/bioc-devel



-- 
Michael Lawrence
Senior Scientist, Bioinformatics and Computational Biology
Genentech, A Member of the Roche Group
Office +1 (650) 225-7760
michafla using gene.com

Join Genentech on LinkedIn | Twitter | Facebook | Instagram | YouTube



More information about the Bioc-devel mailing list