Skip to content

Instantly share code, notes, and snippets.

@christopherlovell
Created July 23, 2015 10:30
Show Gist options
  • Save christopherlovell/7459147f2c8ff611ddaf to your computer and use it in GitHub Desktop.
Save christopherlovell/7459147f2c8ff611ddaf to your computer and use it in GitHub Desktop.
Hidden Rcpp functions
To make a function written in Rcpp hidden, add the following 'name; attribute to the export header line with a period prefix
// [[Rcpp::export(name=".ngram_generator")]]
std::vector<std::string> ngram_generator(std::string sentence, unsigned int n){
std::istringstream iss(sentence);
std::vector<std::string> tokens;
std::vector<std::string> bigrams;
std::string str;
copy(std::istream_iterator<std::string>(iss),
std::istream_iterator<std::string>(),
back_inserter(tokens));
for (unsigned int i = n; i <= tokens.size(); ++i){
str = tokens[i - n];
for (unsigned int j = i - n + 1; j < i; j++){ str = str + ' ' + tokens[j]; }
bigrams.push_back(str);
}
return(bigrams);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment