Question

My program deals with clustering. Apart from dataset user has to specify some details concerning clusters. There are two ways to approach that: you specify number of clusters or prepare list of clusters' descriptions.

args <- list(dataset=points, K=5)
args <- list(dataset=points, clusters=list(
                             list(type="spherical",radius=4),
                             list(type="covariance",covMat=matrix)
                                          )

next you call proper function (my program) in R with args as the argument.

classification <- CEC(args)

I would like to prepare CEC like below

SEXP CEC(SEXP args) {
  Rcpp::List list(args);
  arma::mat dataset = Rcpp::as<arma::mat>(list["dataset"]);
  if(list.contains("K")) {
    //something
  } else if(list.contains("clusters")) {
    //something
  }
}

I cannot find any API for List or example how to do that. Moreover, I study headers of Rcpp but definition of List which is typedef Vector<VECSXP> List ; is hardly helpful.

Is there anything I can use instead of list.contains() ?

Was it helpful?

Solution

You are probably looking for the containsElementNamed method:

Rcpp::List list(args);
if( list.containsElementNamed("K") ){
    // something
} else {
    // something else
}

https://github.com/RcppCore/Rcpp/blob/master/inst/include/Rcpp/vector/Vector.h#L584

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top