Created
September 15, 2017 17:26
-
-
Save nacnudus/01fc48e6a5c0389f1d48a1962ceb67e6 to your computer and use it in GitHub Desktop.
Rcpp NA values vs std::vector<something>
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Rcpp NAs vs std::vector | |
library(Rcpp) | |
cppFunction(" | |
List test1() { | |
return List::create( | |
NumericVector::create(NA_REAL), | |
IntegerVector::create(NA_INTEGER), | |
LogicalVector::create(NA_LOGICAL), | |
CharacterVector::create(NA_STRING)); | |
} | |
") | |
test1() | |
# [[1]] | |
# [1] NA | |
# | |
# [[2]] | |
# [1] NA | |
# | |
# [[3]] | |
# [1] NA | |
# | |
# [[4]] | |
# [1] NA | |
# | |
library(Rcpp) | |
cppFunction(" | |
List test2() { | |
std::vector<double> vdouble; vdouble.push_back(NA_REAL); | |
std::vector<int> vint; vint.push_back(NA_INTEGER); | |
std::vector<bool> vbool; vbool.push_back(NA_LOGICAL); | |
std::vector<Rcpp::String> vString; vString.push_back(NA_STRING); | |
return List::create( | |
vdouble, | |
vint, | |
vbool); | |
} | |
") | |
test2() | |
# [[1]] | |
# [1] NA | |
# | |
# [[2]] | |
# [1] NA | |
# | |
# [[3]] | |
# [1] TRUE | |
# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment