SEXP callFunction1(List network, List words, Function testWordContinuity){
SEXP res = testWordContinuity(network, words);
return res;
}
for(int i=0; i<(n_epochs); i++){
NumericVector outputMatchTracker = history["output.match.tracker"];
outputMatchTracker[i] = callFunction1(network, words, testWordContinuity);
}
The testWordContinuity function in R calls another function in R that returns a single numeric variable
All I'm doing with res is replacing values in a vector using the for loop. The first line after the beginning of the for loop is assigning outputMatchTracker to a vector of zeros (history["output.match.tracker"]) so I can loop over the zeros.
The error: "Cannot convert 'SEXP' to 'Rcpp::traits::storage_type<14>::type {aka double}' in assignment" occurs on the last line in the for loop above.
Is there a way to convert res from SEXP to float or double?
I realize a similar question has been asked here: Rcpp cannot convert ‘SEXP {aka SEXPREC*}’ to ‘double’ in initialization but that question was solved by using an Rcpp sugar function instead of an R function to avoid converting SEXP into a double.
If there is not a way to convert from SEXP to float or double, is there a common way to get around this problem besides just coding the R function in Rcpp?
Happy to provide more information if necessary,
Thank you.
Edit:
Minimum Reproducible Example:
In Rcpp:
// [[Rcpp::export]]
SEXP callFunction(Function func){
SEXP res = func();
return(res);
}
// [[Rcpp::export]]
NumericVector func1(Function func){
for(int i=0; i<10; i++){
NumericVector vect(10);
vect[i] = callFunction(func);
}
return(vect);
}
Upon sourcing this code the error specified above will appear.