1

I want to use the npregbw function from the np package when developing my own Rcpp package.

Inspired by this, I created the following Rcpp function inside my package to make the call.

vec np_cv_bw(mat x, vec  y){


  Rcpp::Environment base("package:np");

  Rcpp::Function npregbw = base["npregbw"];

  List res= npregbw(Rcpp::_["xdat"] = x,
                    Rcpp::_["ydat"]  = Rcpp::NumericVector(y.begin(), y.end()));

  return as<vec>(res["bw"]);


}

However, I just realize that the above code cannot only work inside the R package environment. I got the following error

Cannot convert object to an environment: [type=character; target=ENVSXP]

My question is how I should modify the above function to make a call to an R function from another package in an Rcpp script for my own package?

Ding Li
  • 673
  • 1
  • 7
  • 19
  • Does this answer your question? [Rcpp trouble importing 'hessian' from R package 'numDeriv'](https://stackoverflow.com/questions/53230845/rcpp-trouble-importing-hessian-from-r-package-numderiv) – caldwellst Nov 30 '21 at 09:19

0 Answers0