[Rcpp-devel] Rcpp: Error: not compatible with requested type

Pierre Lafaye de Micheaux lafaye at DMS.UMontreal.CA
Fri Oct 3 18:04:14 CEST 2014


Dear members of the list,

I have a problem using Rcpp in one of my packages. It tried the best I 
could to simplify my code so that the error is reproducible and this is 
what I was able to obtain.
The code is self contain (really, I checked) and as minimal as possible 
(at least for me, sorry for not being able to simplify it further).

I work under Linux with R 3.1.1.

I have this C++ code:

|#include <R.h>
#include <Rcpp.h>
using namespace Rcpp;
extern"C"  {
   SEXP gensampleRcpp2(  Function rlawfunc,  SEXP n)  {
     Rcpp::RNGScope __rngScope;
     return  Rcpp::List::create(Rcpp::Named("sample")  =  rlawfunc(n),
                    Rcpp::Named("law.name")  =  "",
                    Rcpp::Named("law.pars")  =  R_NilValue);
   }

   RcppExport SEXP gensampleRcpp(SEXP rlawfuncSEXP,  SEXP nSEXP)  {
     BEGIN_RCPP
     Function rlawfunc=  Rcpp::as<Function>(rlawfuncSEXP);
     IntegerVector n=  Rcpp::as<IntegerVector>(nSEXP);
     SEXP __result=  gensampleRcpp2(rlawfunc,  n);
     return  Rcpp::wrap(__result);
     END_RCPP
       }

   SEXP compquantRcpp2(IntegerVector n,  IntegerVector M,  Function Rlaw)  {
     int i;
     GetRNGstate();
     for  (i=1;i<=M[0];i++)  {
     List resultsample=  gensampleRcpp2(Rlaw,  n);
     NumericVector mysample=  Rcpp::as<NumericVector>(resultsample["sample"]);
     }
     PutRNGstate();
     return  Rcpp::List::create(Rcpp::Named("law.pars")  =  "");
   }

   RcppExport SEXP compquantRcpp(SEXP nSEXP,  SEXP MSEXP,  SEXP RlawSEXP)  {
     BEGIN_RCPP
     IntegerVector n=  Rcpp::as<IntegerVector>(nSEXP);
     IntegerVector M=  Rcpp::as<IntegerVector>(MSEXP);
     Function Rlaw=  Rcpp::as<Function>(RlawSEXP);
     SEXP __result=  compquantRcpp2(n,  M,  Rlaw);
     return  Rcpp::wrap(__result);
     END_RCPP
       }
}|

and this R code:

|compquant<-  function(n=50,M=10^3,Rlaw=rnorm)  {
   out<-  .Call("compquantRcpp",n=as.integer(n),M=as.integer(M),as.function(Rlaw),PACKAGE="PoweR")  
   return(out)
}|

in a package called PoweR (in fact the above codes are simplifications 
of my own code so do no try to understand the statistical purpose of it).

When I compile my package (under Linux and R version 3.1.0) and issue 
the following R command in the console:

|require(PoweR)
compquant()

|

I get the following error: *Error: not compatible with requested type*

Do you have any idea on what could be the problem and how to solve it? 
Or any idea on simplifying further?

Many thanks in advance for any idea.

Best regards,

Pierre Lafaye de Micheaux

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20141003/b568c49b/attachment.html>


More information about the Rcpp-devel mailing list