[Rcpp-devel] Feedining an IntegerVector into Rcout?
Søren Højsgaard
sorenh at math.aau.dk
Sat Nov 17 00:28:56 CET 2012
Dear list,
Sorry for a trivial question: I have created the function below which calls "match" on each vector in a list and returns the result as a list. The function does what I want it to, but I am puzzled by this:
+ IntegerVector out = R_match(wrap(ee), V_);
+ Rcout << out << std::endl;
which prints
0xca858e0
0xca85cd0
0xd715d80
0xd715db8
- which proves that there is something not clear to me: Can't I print an entire vector with Rcout - or must I exctract each element and print separately (which seems kludgy)?
Best regards
Søren
> get_index_ <- cxxfunction(signature(x_ = "SEXP", V_="SEXP"), plugin = "Rcpp",
+ body = '
+ using namespace Rcpp;
+ using namespace std;
+ Function R_match("match");
+ CharacterVector V(V_);
+ List x(x_);
+ List res=List::create();
+ for (int ii=0; ii<x.length(); ii++){
+ CharacterVector ee = as<CharacterVector>(x[ii]);
+ IntegerVector out = R_match(wrap(ee), V_);
+ Rcout << out << std::endl;
+ res.push_back(out);
+ }
+ return(wrap(res));
+ ')
>
> get_index_(list(c("a","b"),c("b","c"), c("a","c","e"), c("a","c","q")), letters[1:10])
0xca858e0
0xca85cd0
0xd715d80
0xd715db8
[[1]]
[1] 1 2
[[2]]
[1] 2 3
[[3]]
[1] 1 3 5
[[4]]
[1] 1 3 NA
More information about the Rcpp-devel
mailing list