Search code examples
crr-bigmemory

R package development: how to check whether the type of SEXP is "big.matrix"?


I am developing an R package with low-level C code. Suppose I have following function in my C code.

SEXP myFun(SEXP obj)

I need to know whether the R object obj is a regular matrix or big.matrix (use R package bigmemory) so that I can call different functions for computation.

Is this possible? How could I know the class type of obj?


Solution

  • You can use the inherits function:

    #include <R.h>
    #include <Rinternals.h>
    
    SEXP myFun(SEXP obj) {
        if (inherits(obj, "big.memory")) {
            // do stuff
        }
    }