[Rcpp-devel] Rcpp: Error: not compatible with requested type
Dirk Eddelbuettel
edd at debian.org
Fri Oct 3 18:36:36 CEST 2014
Pierre,
It is not clear what your code is actually trying to do. The following
should be equivalent (as best as I can tell), works (!!) and makes life a lot
easier via Attributes.
------- save this as eg /tmp/pierre.cpp -------------------------------------
#include <Rcpp.h>
// [[Rcpp::export]]
Rcpp::List newCompQuant(int n, int M, Rcpp::Function f) {
Rcpp::Rcout << "n : " << n << std::endl
<< "M : " << M << std::endl;
return Rcpp::List::create(Rcpp::Named("sample") = f,
Rcpp::Named("law.name") = " ",
Rcpp::Named("law.pars") = R_NilValue);
}
/*** R
res <- newCompQuant(n=50, M=10^3, f=norm)
print(str(res))
*/
-----------------------------------------------------------------------------
In R, then do
R> Rcpp::sourceCpp("/tmp/pierre.cpp")
for which I then get:
R> sourceCpp("/tmp/pierre.cpp")
R> res <- newCompQuant(n=50, M=10^3, f=rnorm)
n : 50
M : 1000
R> print(str(res))
List of 3
$ sample :function (n, mean = 0, sd = 1)
$ law.name: chr " "
$ law.pars: NULL
NULL
R>
Attributes also take care of RNGScope, and past discussions here have seen it
help with repeated calls (with a 'big' N of number of repeats) where manually
dealing with scope and temp objects may otherwise create a wrinkle.
Hth, Dirk
--
http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org
More information about the Rcpp-devel
mailing list