我定義中的R C++函數,它是:無法調用RCPP的階乘功能的一個標量
library(Rcpp)
cppFunction(
'double foo(double t, int k) {
double x = t/factorial(k);
}')
當運行中的R這個功能時,收到一個錯誤:
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)) ; }
有誰能幫我解決這個問題嗎?謝謝!
你也應該找到不從函數返回的任何錯誤(我想你需要一個'返回X;'聲明 – SymbolixAU
@SymbolixAU即使我添加此return語句時,問題仍然存在 – Lin