Created
March 22, 2018 14:57
-
-
Save ginolhac/3b65c31ca59524d9023f95eb060ddf0c to your computer and use it in GitHub Desktop.
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
#include <Rcpp.h> | |
using namespace Rcpp; | |
// [[Rcpp::export]] | |
SEXP with_string(CharacterVector names) { | |
int size = names.size(); | |
std::vector<String> tmp; | |
String strtmp; | |
CharacterVector out_vec(tmp.begin(), tmp.end()); | |
for (int i = 0; i < size; ++i) { | |
strtmp = names[i]; | |
tmp.push_back(strtmp); | |
} | |
return out_vec; | |
} | |
// [[Rcpp::export]] | |
SEXP with_stdstr(CharacterVector names) { | |
int size = names.size(); | |
std::vector<std::string> tmp; | |
String strtmp; | |
CharacterVector out_vec(tmp.begin(), tmp.end()); | |
for (int i = 0; i < size; ++i) { | |
strtmp = names[i]; | |
tmp.push_back(strtmp); | |
} | |
return out_vec; | |
} | |
/*** R | |
system.time(a <- with_string(paste0("col_", 1:50000))) | |
system.time(b <- with_stdstr(paste0("col_", 1:50000))) | |
identical(a, b) | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment