return NA via RCpp
r, rcpp
Solution
The canonical way to get the correct `NA` for a given vector type (`NumericVector`, `IntegerVector`, ...) is to use the static `get_na` method. Something like:
y[0] = NumericVector::get_na() ;
FWIW, your code works as is with `Rcpp11`, which knows how to convert from the static `Na_Proxy` instance `NA` into the correct missing value for the target type.
Problem
Newbie RCpp question here: how can I make a NumericVector return `NA` to R? For example, suppose I have a RCpp code that assigns `NA` to the first element of a vector. ``` // [[RCpp::export]] NumericVector myFunc(NumericVector x) { NumericVector y=clone(x); y[0]=NA; // <----- what's the right expression here? return y; } ```