From mario.annau at gmail.com  Sat Jan 24 09:58:29 2015
From: mario.annau at gmail.com (Mario Annau)
Date: Sat, 24 Jan 2015 09:58:29 +0100
Subject: [Rd] Proper way to define cbind, rbind for s4 classes in package
Message-ID: <54C35EB5.3060402@gmail.com>

Hi all,
this question has already been posted on stackoverflow, however without
success, see also
http://stackoverflow.com/questions/27886535/proper-way-to-use-cbind-rbind-with-s4-classes-in-package.

I have written a package using S4 classes and would like to use the
functions rbind, cbind with these defined classes.

Since it does not seem to be possible to define rbind and cbind directly
as S4 methods (see ?cBind) I defined rbind2 and cbind2 instead:

setMethod("rbind2", signature(x="ClassA", y = "ANY"),
    function(x, y) {
      # Do stuff ...
})

setMethod("cbind2", signature(x="ClassA", y = "ANY"),
    function(x, y) {
      # Do stuff ...
})

>From ?cbind2 I learned that these functions need to be activated using
methods:::bind_activation to replace rbind and cbind from base.

I included the call in the package file R/zzz.R using the .onLoad function:

.onLoad <- function(...) {
  # Bind activation of cbind(2) and rbind(2) for S4 classes
  methods:::bind_activation(TRUE)
}
This works as expected. However, running R CMD check I am now getting
the following NOTE since I am using an unexported function in methods:

* checking dependencies in R code ... NOTE
Unexported object imported by a ':::' call: 'methods:::bind_activation'
  See the note in ?`:::` about the use of this operator.
How can I get rid of the NOTE and what is the proper way to define the
methods cbind and rbind for S4 classes in a package?

Best,
mario



[Rd] Proper way to define cbind, rbind for s4 classes in package
Mario Annau