In my understanding, converting vectors between Rcpp and C++ creates new vectors as follows. Is my understanding right?
When converting an Rcpp vector to a C++ vector, we use Rcpp::as<T>()
(e.g. Rcpp::as<std::string>
for Rcpp::CharacterVector
).
std::vector<std::string>
is created, and the original Rcpp elements are copied into the C++ vector as std::string
.
This means that modifying the newly created C++ vector elements does not affect the original Rcpp vector elements.
When converting a C++ vector to an Rcpp vector, we use Rcpp::wrap()
.
Rcpp vector with the corresponding type is created, and the C++ elements are copied into the Rcpp vector as Rcpp objects. This means that modifying the newly created Rcpp vector elements does not affect the original C++ vector elements.