I am writing a small R package with the idea to submit it to Bioconductor in the future, which is why I decided to try out s4 classes. Unfortunately I had problems understanding when I should use setGeneric or not in my package, and the documentation for the setGeneric method is for me more or less incomprehensible.
Concrete example:
- I created a s4 class called Foo
- I defined a method for the
[<-operator usingsetMethod("[","Foo", ...) - I defined a method for the
as.listfunction usingsetMethod("as.list", "Foo",...) - I avoided using
setGenericsand exporting my methods in the namespace as I read somewhere that it's not needed for already defined generic functions
The problem now is that the [ accessor method works like a charm, but as.list is not working. Even more confusing, when I import the library BiocGenerics by typing library(BiocGenerics) at the R terminal, as.list starts to work.
Question 1: how can I be sure that [ will always work? And it is not just a coincidence because I imported some libraries?
Question 2: what should I do to make as.list work? Export the method in the namespace? use setGeneric?
Question 3: I thought that as.list started to work because setGeneric("as.list"...) was used in the BiocGenerics package, but this does not seem to be the case, reading from here: http://www.bioconductor.org/packages/release/bioc/manuals/BiocGenerics/man/BiocGenerics.pdf
So why did as.list start to work? Where was it defined?