如何在 64 位向量中将 NA 值从 Rcpp 传递到 R?
我的第一种方法是:
// [[Rcpp::export]]
Rcpp::NumericVector foo() {
Rcpp::NumericVector res(2);
int64_t val = 1234567890123456789;
std::memcpy(&(res[0]), &(val), sizeof(double));
res[1] = NA_REAL;
res.attr("class") = "integer64";
return res;
}
但它产生
#> foo()
integer64
[1] 1234567890123456789 9218868437227407266
我需要得到
#> foo()
integer64
[1] 1234567890123456789 <NA>