This package was begun as an investigation of how to discover methods – defined in different packages – that convert class instances.

More recently, the task of generating R code for class definitions with getters and setters came up, and some demonstrative code was added.

Coercions

To clarify, enumeration of coercion methods can involve searching across packages. We provide code to produce lists; the package harboring the coercion method is hidden in this display:

 $SingleCellExperiment
 [1] "from=\"RangedSummarizedExperiment\", to=\"SingleCellExperiment\""
 [2] "from=\"SummarizedExperiment\", to=\"SingleCellExperiment\""      
 
 $SummarizedExperiment
 [1] "from=\"ExpressionSet\", to=\"SummarizedExperiment\""             
 [2] "from=\"RangedSummarizedExperiment\", to=\"SummarizedExperiment\""
 [3] "from=\"SummarizedExperiment\", to=\"ExpressionSet\""             
 [4] "from=\"SummarizedExperiment\", to=\"RangedSummarizedExperiment\""
 [5] "from=\"SummarizedExperiment\", to=\"SingleCellExperiment\""      
 
 $RangedSummarizedExperiment
 [1] "from=\"ExpressionSet\", to=\"RangedSummarizedExperiment\""       
 [2] "from=\"RangedSummarizedExperiment\", to=\"ExpressionSet\""       
 [3] "from=\"RangedSummarizedExperiment\", to=\"SingleCellExperiment\""
 [4] "from=\"RangedSummarizedExperiment\", to=\"SummarizedExperiment\""
 [5] "from=\"SummarizedExperiment\", to=\"RangedSummarizedExperiment\""

Code generation

Following a nice discussion in Stuart Lee’s blog, we can produce, on the basis of a prototypical list, the code:

 setClass('Turtle', slots= c(location='numeric', orientation='numeric', path='matrix'), 
     prototype=list(location = c(0, 0), orientation = 0, path = structure(c(0, 0), .Dim = 1:2)))
 setGeneric(name='location', def=function(x) standardGeneric('location'))
 setMethod(f='location', signature='Turtle', function(x) slot(x, 'location'))
 setGeneric(name='orientation', def=function(x) standardGeneric('orientation'))
 setMethod(f='orientation', signature='Turtle', function(x) slot(x, 'orientation'))
 setGeneric(name='path', def=function(x) standardGeneric('path'))
 setMethod(f='path', signature='Turtle', function(x) slot(x, 'path'))
 setGeneric(name='location<-', def=function(x, value) standardGeneric('location<-'))
 setMethod(f='location<-', signature='Turtle', function(x, value) {slot(x, 'location') = value; x})
 setGeneric(name='orientation<-', def=function(x, value) standardGeneric('orientation<-'))
 setMethod(f='orientation<-', signature='Turtle', function(x, value) {slot(x, 'orientation') = value; x})
 setGeneric(name='path<-', def=function(x, value) standardGeneric('path<-'))
 setMethod(f='path<-', signature='Turtle', function(x, value) {slot(x, 'path') = value; x})

We can also generate the additional code required of a class extension.