Rcpp: Error: Incompatible with the requested type

I have 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 (actually the above codes are simplifying my own code, so don't try to understand its purpose). 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 am getting the following error: Error: Incompatible with the requested type

Do you have any idea what the problem might be and how to solve it?

Thank.

+3


source to share


1 answer


I just needed to remove the 6th line: Rcpp :: RNGScope __rngScope; solve the problem of. This suggests that Dirk Eddelbuettel gave very good hints to rcpp-devel on how to greatly simplify the entire process. So many thanks to Dirk.



0


source







All Articles