-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest.cpp
More file actions
36 lines (32 loc) · 763 Bytes
/
test.cpp
File metadata and controls
36 lines (32 loc) · 763 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <Rcpp.h>
using namespace Rcpp;
// include after Rcpp.h:
#include <stringi.h>
//' Duplicates a given string
//' @param x a character vector
//' @param i an integer vector
//' @return a character vector
//'
//' @examples
//' test_dup("A", 1)
//'
//' @export
// [[Rcpp::export]]
CharacterVector test_dup(CharacterVector x, IntegerVector i) {
return stri_dup(x, i);
}
//' Concatenates all strings into a single one
//' @param x a character vector
//' @return a character vector
//'
//' @examples
//' test_paste(letters)
//'
//' @export
// [[Rcpp::export]]
CharacterVector test_paste(CharacterVector x) {
IntegerVector y(seq_len(x.size()));
CharacterVector u = stri_join2(x, y);
u = stri_flatten(u, CharacterVector(", "));
return u;
}