Skip to content

Instantly share code, notes, and snippets.

@nacnudus
Created September 15, 2017 17:26
Show Gist options
  • Save nacnudus/01fc48e6a5c0389f1d48a1962ceb67e6 to your computer and use it in GitHub Desktop.
Save nacnudus/01fc48e6a5c0389f1d48a1962ceb67e6 to your computer and use it in GitHub Desktop.
Rcpp NA values vs std::vector<something>
# 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