我正在尝试重现基于 R 帮助的 R 示例。 这是内联包中的 cxxfunction 示例。
require(Rcpp)
require(inline)
# Rcpp plugin
if( require( Rcpp ) ){
fx <- cxxfunction( signature(x = "integer", y = "numeric" ) , '
return wrap( as<int>(x) * as<double>(y) ) ;
', plugin = "Rcpp" )
fx( 2L, 5 )
## equivalent shorter form using rcpp()
fx <- rcpp(signature(x = "integer", y = "numeric"),
' return wrap( as<int>(x) * as<double>(y) ) ; ')
}
我收到这条消息:
compileCode(f, code, language = language, verbose = verbose) 错误:
编译错误,未创建函数/方法!警告信息:
运行命令'make -f "C:/PROGRA~1/R/R-30~1.3/etc/i386/Makeconf"-f "C:/PROGRA~1/R/R-30~1.3/share/make/winshlib.mk"....
此外:
警告信息:
运行命令 'C:/PROGRA~1/R/R-30~1.3/bin/i386/R CMD SHLIB file3a86e316ef8.cpp ...
我正在使用:
平台 i386-w64-mingw32 和 R-3.0.3
最佳答案
正如凯文所说,它更容易使用属性。属性 //[[Rcpp::export]]
为您完成所有工作。
安装了 R
和 Rcpp
的当前版本后,创建一个名为 test.cpp
的文件来放置此代码:
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
double fx(int x, double y){
return x*y;
}
/*** R
fx(2L,5)
fx(2L,5.1)
*/
然后在 R
session 中运行:Rcpp::sourceCpp('test.cpp')
如果您按照说明安装 R
、R-tools
并设置 PATH
变量(如果在 Windows 上),那应该可行正确。
关于c++ - cxxfunction 错误消息,内联 R 包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25491717/