Skip to content
Prev 1411 / 10988 Next

[Rcpp-devel] idiom for determining the (S3) class of an R object?

There is a related routine in R_HOME/src/main/attrib.c:

EXP R_data_class(SEXP obj, Rboolean singleString)
{
     SEXP value, klass = getAttrib(obj, R_ClassSymbol);
     int n = length(klass);
     if(n == 1 || (n > 0 && !singleString))
     return(klass);
     if(n == 0) {
     SEXP dim = getAttrib(obj, R_DimSymbol);
     int nd = length(dim);

This is designed to handle S3 or S4 and with the second argument to get 
the single string needed.  It is not in the API, unfortunately, but it 
is called rather directly from the primitive that  implements class().  
Worth consulting at least.

John
On 12/2/10 1:51 PM, Dirk Eddelbuettel wrote: