r - Check if element of list of matrix are na in rcpp -


this question has answer here:

i have list of matrix , of them na, following:

listtocheck <- list(na, matrix(0,nrow = 2, ncol = 2)) 

and write code in rcpp check if element of list na or not.

i tried 2 following,

// [[rcpp::depends(rcpparmadillo)]] #include <rcpparmadillo.h> using namespace rcpp;  // [[rcpp::export]] bool checkna(int i, list elemincluster){     arma::mat matrix = elemincluster[i];     if(r_isna(matrix(0,0))){      return true;    }     return false; } 

but doesn't work when try checkna(0, listtocheck) gives error in checkna(0, listtocheck) : not matrix. try access first element when matrix na.

as r_isna works on double, there way check matrix na without having access 1 of elements?

using try-catch in this example seems work:

#include <rcpp.h> using namespace rcpp;  // [[rcpp::export]] bool checkna(int i, list elemincluster){    try {     return r_isna(elemincluster[i]);   } catch(...) {     return false;   } }   > checkna(0, listtocheck) [1] true  > checkna(1, listtocheck) [1] false 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -