1 #include <Rcpp.h>
2 using namespace Rcpp;
3 
4 typedef ListOf<NumericVector> NVList;
5 
6 // [[Rcpp::export]]
test_identity(NVList x)7 NVList test_identity(NVList x) {
8     return x;
9 }
10 
11 template <typename T>
sum_(const T & x)12 double sum_(const T& x) {
13     return sum(x);
14 }
15 
16 // [[Rcpp::export]]
test_lapply_sum(NVList x)17 List test_lapply_sum(NVList x) {
18     return lapply(x, sum_<NumericVector>);
19 }
20 
21 // [[Rcpp::export]]
test_sapply_sum(NVList x)22 NumericVector test_sapply_sum(NVList x) {
23     return sapply(x, sum_<NumericVector>);
24 }
25 
26 // [[Rcpp::export]]
test_assign(NVList x,NumericVector y,CharacterVector z)27 NVList test_assign(NVList x, NumericVector y, CharacterVector z) {
28     x[1] = y;
29     x[2] = 1;
30     return x;
31 }
32 
33 // [[Rcpp::export]]
test_assign_names(NVList x)34 NVList test_assign_names(NVList x) {
35     x["a"] = x["b"];
36     return x;
37 }
38 
39 
40 // [[Rcpp::export]]
test_add(NVList x)41 NumericVector test_add(NVList x) {
42     return x[0] + x[1] + x[2];
43 }
44 
45 // [[Rcpp::export]]
test_add_subtract(NVList x)46 NumericVector test_add_subtract(NVList x) {
47     return x[0] + x[1] - x[2];
48 }
49 
50 // [[Rcpp::export]]
test_mult(NVList x)51 NumericVector test_mult(NVList x) {
52     return x[0] * x[1] * x[2];
53 }
54 
55 typedef ListOf<CharacterVector> CVList;
56 // [[Rcpp::export]]
test_char(CVList x)57 CVList test_char(CVList x) {
58     x[0] = "apple";
59     return x;
60 }
61 
62 // [[Rcpp::export]]
test_as_wrap(NVList x)63 NVList test_as_wrap(NVList x) {
64     List y = as<List>(x);
65     NVList z = as<NVList>(y);
66     NumericVector k = x[0];
67     x[0] = z[1];
68     return z;
69 }
70 
71 // [[Rcpp::export]]
test_add_NV(NVList x,NumericVector y)72 NumericVector test_add_NV(NVList x, NumericVector y) {
73     return y + x[0];
74 }
75 
76 // [[Rcpp::export]]
test_binary_ops(NVList x)77 NVList test_binary_ops(NVList x) {
78     return List::create(
79         x[0] > x[1],
80         x[0] < x[1],
81         x[0] >= x[1],
82         x[0] <= x[1]
83     );
84 }
85 
86 #if defined(_WIN32)
87 typedef int retval;
88 #else
89 typedef R_xlen_t retval;
90 #endif
91 // [[Rcpp::export]]
test_sub_calls(NVList x)92 retval test_sub_calls(NVList x) {
93     retval sz = x[0].size() + x[1].size() + x[2].size();
94     return sz;
95 }
96 
97 // [[Rcpp::export]]
test_nested_listof(ListOf<ListOf<NumericVector>> x)98 NumericVector test_nested_listof(ListOf< ListOf<NumericVector> > x) {
99   return x[0][0];
100 }
101 
102 // [[Rcpp::export]]
test_return_IVList(List x)103 ListOf<IntegerVector> test_return_IVList(List x) {
104     return x;
105 }
106 
107 // [[Rcpp::export]]
listof_names(ListOf<NumericVector> x)108 CharacterVector listof_names(ListOf<NumericVector> x) {
109     return x.names();
110 }
111 
112 // [[Rcpp::export]]
listof_attr_foo(ListOf<NumericVector> x)113 SEXP listof_attr_foo(ListOf<NumericVector> x) {
114     return x.attr("foo");
115 }
116