[R] "Overloading" some non-dispatched S3 methods for new classes

Carlos J. Gil Bellosta cgb at datanalytics.com
Sat May 9 20:50:19 CEST 2009


Hello,

I am building a package that creates a new kind of object not unlike a
dataframe. However, it is not an extension of a dataframe, as the data
themselves reside elsewhere. It only contains "metadata".

I would like to be able to retrieve data from my objects such as the
number of rows, the number of columns, the colnames, etc.

I --quite naively-- thought that ncol, nrow, colnames, etc. would be
dispatched, so I would only need to create a, say, ncol.myclassname
function so as to be able to invoke "ncol" directly and transparently.

However, it is not the case. The only alternative I can think about is
to create decorated versions of ncol, nrow, etc. to avoid naming
conflicts. But I would still prefer my package users to be able to use
the undecorated function names.

Do I have a chance?

Best regards,

Carlos J. Gil Bellosta
http://www.datanalytics.com




More information about the R-help mailing list