[Rcpp-devel] is_na, is_infinite etc

Dirk Eddelbuettel edd at debian.org
Thu Jan 23 02:10:47 CET 2014


On 22 January 2014 at 23:07, Søren Højsgaard wrote:
| I am struggeling with checking for NA and Inf in a loop over a numeric vector. I have created these two helpers:

"If in doubt, check unit tests". 

See e.g. inst/unitTests/cpp/sugar.cpp 

// [[Rcpp::export]]
LogicalVector runit_isna( NumericVector xx){
    return wrap( is_na( xx ) ) ;
}

// [[Rcpp::export]]
LogicalVector runit_isfinite( NumericVector xx){
    return is_finite(xx) ;
}

// [[Rcpp::export]]
LogicalVector runit_isinfinite( NumericVector xx){
    return is_infinite(xx) ;
}

// [[Rcpp::export]]
LogicalVector runit_isnan( NumericVector xx){
    return is_nan(xx) ;
}

These save you the loop. But if you want to you do of course the plain C
functions from the R interface.

Dirk


-- 
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com


More information about the Rcpp-devel mailing list