Skip to content
Prev 2288 / 21307 Next

[Bioc-devel] Extend class definition on attaching a package

On 08/26/2010 05:58 PM, Venkatraman Seshan wrote:
I guess you're trying to develop a package that has functionality that
has code that is conditional on the bigmemory package -- if bigmemory is
available then do one thing, otherwise do another. But this is not, in
my opinion, a good idea -- your user gets different behavior on Monday
versus Wednesday (because they installed bigmemory on Tuesday) and you
have two code branches to maintain (which leads to headaches, as
evidenced by this thread!). So I think you really just want to

  Imports: bigmemmory

in your DESCRIPTION file,

importClassesFrom(bigmemory, big.matrix)

in NAMESPACE

and

setClassUnion("cnmatrix", c("matrix", "big.matrix"))
setClass("mydata",
         representation=representation(x="numeric", y="cnmatrix"))

in the 'top level' (i.e., not in .onLoad or other function call) of some
R/*R file.

Actually my stronger advice is that you avoid the setClassUnion --
you're really saying that your 'cnmatrix' walks and talks exactly like a
matrix and a big.matrix, and vice versa, when really you have no control
over what methods are defined for matrix or big.matrix (any package can
define methods for these classes) so you have no idea whether the
methods are appropriate for cnmatrix. Better in my opinion to implement
the interface that is directly relevant to cnmatrix, even if it is often
simple delegation to a 'matrix' slot of cnmatrix.

Martin