[Rcpp-devel] Segfaults

Hadley Wickham hadley at rice.edu
Wed Jan 4 15:55:29 CET 2012


> So your i_[0] - 1 is also nan. You are responsible for dealing with na.
>
> You can use traits::is_na:
>
> fx <- cxxfunction( signature( x_ = "numeric"), '
>
>    double x = as<double>(x_) ;
>
>    if( traits::is_na<REALSXP>(x) ){
>        // do something
>    } else {
>        // do something else
>    }
>
> ', plugin = "Rcpp" )
>
> or perhaps if you don't like the whole traits::is_na<REALSXP> thing, you
> could use e.g. somethin like this:
>
> template <typename T>
> bool isna( T x ){
>    return traits::is_na<traits::r_sexptype_traits<T>::rtype > (x) ;
> }
>
> so that you coud just call
>
> if( isna(x) ){ ... }

What are the advantages/disadvantages of doing that over (say) x_[i]
== NA_REAL ?

Hadley

-- 
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/


More information about the Rcpp-devel mailing list