/
r-accessor-to-code.cpp
66 lines (55 loc) · 1.82 KB
/
r-accessor-to-code.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <Rcpp.h>
// Load subdirectory header files
#include "A/routineA.h"
#include "B/routineB.h"
//' Using Both Subdirectory Functions
//'
//' These function serve as intermediaries between R and the subdirectory
//' source.
//'
//' @param x Vector of Numeric Values with length \eqn{n}.
//'
//' @return A vector of numeric values with length \eqn{n}.
//'
//' @rdname exported_funcs
//' @export
//' @examples
//' my_vec = c(3.5, 8, -1.5, -2, 0, 42)
//' calc_modifications(my_vec)
// [[Rcpp::export]]
Rcpp::NumericVector calc_modifications(Rcpp::NumericVector x) {
// Calculate the modification from the A routine
Rcpp::NumericVector A = calc_A_routine(x);
// Calculate the modification from the B routine
Rcpp::NumericVector B = calc_B_routine(x);
// Calculate the element-wise total.
Rcpp::NumericVector C = A + B;
return C;
}
//' @rdname exported_funcs
//' @export
//' @details
//' The exported function name is different from the subdirectory function.
//' C++ does not allow duplicate function names with the same parameters. To
//' preserve the original function name necessitates the subdirectory function
//' being placed behind a namespace, e.g. `A::calc_A_routine()`. Otherwise,
//' the name of the function exported must be different, e.g. `calc_A_export()`.
//'
//' @examples
//' my_vecA = c(881, 884, 1,2,-4)
//' calc_A_export(my_vec)
// [[Rcpp::export]]
Rcpp::NumericVector calc_A_export(Rcpp::NumericVector x) {
// Calculate the modification from the A routine and return it
return calc_A_routine(x);
}
//' @rdname exported_funcs
//' @export
//' @examples
//' my_vecB = c(512,32, -1, 1.3, 5.9)
//' calc_B_export(my_vecB)
// [[Rcpp::export]]
Rcpp::NumericVector calc_B_export(Rcpp::NumericVector x) {
// Calculate the modification from the B routine and return it
return calc_B_routine(x);
}