definiere ich eine C++ Funktion in R nennen, es ist:kann nicht RCPP der Fakultäts-Funktion mit einem Scalar
library(Rcpp)
cppFunction(
'double foo(double t, int k) {
double x = t/factorial(k);
}')
Wenn ich diese Funktion in R ausführen, erhalte ich eine Fehlermeldung:
file59b051c6b334.cpp:7:25: error: no matching function for call to 'factorial'
NumericVector x = t/factorial(k); ^~~~~~~~~
/Library/Frameworks/R.framework/Versions/3.3/Resources/library/Rcpp/include/Rcpp/sugar/functions/math.h:59:19:
note: candidate function not viable: no known conversion from 'int' to 'SEXP' (aka 'SEXPREC *') for 1st argument VECTORIZED_MATH_1(factorial , ::Rcpp::internal::factorial )
/Library/Frameworks/R.framework/Versions/3.3/Resources/library/Rcpp/include/Rcpp/sugar/block/Vectorized_Math.h:91:9:
note: expanded from macro 'VECTORIZED_MATH_1'
__NAME__(SEXP x){ return __NAME__(NumericVector(x)) ; }
Könnte mir bitte jemand helfen, dieses Problem zu lösen? Vielen Dank!
Sie sollten auch eine Fehlermeldung über nicht Rückkehr irgendetwas aus der Funktion (ich glaube, Sie brauchen eine 'return x;' Aussage – SymbolixAU
@SymbolixAU Auch füge ich diese return-Anweisung, die Problem existiert immer noch. – Lin