[R] S4 method signature - integer matrix
Simon Zehnder
szehnder at uni-bonn.de
Fri Jul 19 18:54:28 CEST 2013
Dear R-Users and R-Devels,
I am programming a package with S4 classes and I search for a solution of the following problem:
If you want an S4 method to await an integer argument you set the signature like this
setMethod("myfunction", signature(object = "myClass", y = "integer"), function(object, y) {//Do sth})
Now, if you want the method to await an integer matrix or array there is only one way how to define it
setMethod("myfunction", signature(object = "myClass", y = "matrix"), function(object, y) {//Do sth}) or
setMethod("myfunction", signature(object = "myClass", y = "array"), function(object, y) {//Do sth})
am I right? WIth this you can also pass a numeric matrix.
How would you check for an integer matrix in an S4 method (in the index function of R I think it is just coerced to integer)? Furthermore: How would you check for an integer matrix with values
bigger one (so the typical R indices)? Is there a way how it is usually done in R (I think probably with apply())? Or is it usually better to throw an exception?
Best
Simon
More information about the R-help
mailing list