How can I translate a function in R to Rcpp?

Viewed 105

I need your help because I have a problem in this code. I'm trying to translate R code to Rcpp using functions that are in the library kerdiest. Here I have a basic example of a function in R.

library(kerdiest)
hal<- function(n){
  x<- rnorm(n)
  h_AL<- ALbw(vec_data=x)
  return(h_AL)
}

Then, I made these translations for Rcpp, they send me the error **"'vec_data' was not declared in this scope*"; I don't know which one of the three is the best options, I really don't know the difference, so if you could help me with that too I will be very happy :) (I'm sorry, I'm new in Rcpp)

// [[Rcpp::export]]
NumericVector hal(int n){
  NumericVector prueba= Rcpp:: rnorm(n);
  Environment kerdiest ("package:kerdiest");
  Function F = kerdiest ["ALbw"];
  NumericVector h_AL = F(vec_data =prueba);
 // double h_AL=Rcpp::as<double> F(prueba) ;
  // return (Rcpp::wrap(h_AL));
  return h_AL;
}

// [[Rcpp::export]]
SEXP hal2(int n){
  NumericVector prueba= Rcpp:: rnorm(n);
  Environment kerdiest ("package:kerdiest");
  Function F = kerdiest ["ALbw"];
  SEXP h_AL = F(vec_data=prueba);
  // double h_AL=Rcpp::as<double> F(prueba) ;
  // return (Rcpp::wrap(h_AL));
  return h_AL;
}



// [[Rcpp::export]]
RcppExport SEXP hal3(int n){
  NumericVector prueba= rnorm(n,0,1);
  Environment kerdiest ("package:kerdiest");
  Function F = kerdiest ["ALbw"];
  RNGScope scope;
  NumericVector h_AL = F(vec_data= prueba);
  // double h_AL=Rcpp::as<double> F(prueba) ;
  // return (Rcpp::wrap(h_AL));
  return h_AL;
}

Thank you very much!

0 Answers
Related