-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_2.cpp
42 lines (36 loc) · 945 Bytes
/
test_2.cpp
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
37
38
39
40
41
42
#include <Rcpp.h>
using namespace Rcpp;
// This is a simple example of exporting a C++ function to R. You can
// source this function into an R session using the Rcpp::sourceCpp
// function (or via the Source button on the editor toolbar). Learn
// more about Rcpp at:
//
// http://www.rcpp.org/
// http://adv-r.had.co.nz/Rcpp.html
// http://gallery.rcpp.org/
//
// [[Rcpp::export]]
NumericVector create_empty_vector(int n) {
NumericVector v (n);
return v;
}
// [[Rcpp::export]]
int get_length_vec(NumericVector x) {
int length_vec = x.length();
return length_vec;
}
// [[Rcpp::export]]
void print_i_cpp(int i) {
for(int j = 1; j<=i; j ++){
Rcout << j << "\n";
}
}
// You can include R code blocks in C++ files processed with sourceCpp
// (useful for testing and development). The R code will be automatically
// run after the compilation.
//
/*** R
a = create_empty_vector(10)
get_length_vec(a)
print_i_cpp(3)
*/