[R] Defining default method for S3, S4 and R5 classes

Luca Cerone luca.cerone at gmail.com
Fri Jun 13 12:20:06 CEST 2014


Dear all,

I am writing a script implementing a pipeline to analyze some of the
data we receive.

One of the steps in this pipeline involves clustering the data, and I
am interested
in studying the effects of different clustering algorithms on the final results.

I am having issues making my code general enough because the
clustering algorithms we are interested all return different types of
objects (S3, S4 and R5 classes, as well as simple named lists).

>From the output of these algorithms I need to extract a list with as many
elements as the number of clusters and such that each element contains the ids
of the elements in each cluster.

I have easily done this for each of the cluster algorithms,
the problem is: how can I make so that rather than having to check for
classes and
types this is done automatically?

For example, for the algorithms that return S3 classes I have defined
a method "get_cluster_list.default" and then created the methods for
the individual classes, which is used in the main body of the
pipeline.

I have no idea how I can do this for S4 and R5 classes and,  more
importantly, I would
like an approach that works when using all S3, S4 and R5 classes.

Do you know how I could do this?

Thanks for the help,
Luca



More information about the R-help mailing list