gpt4 book ai didi

c++ - cxxfunction 错误消息,内联 R 包

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:21:34 25 4
gpt4 key购买 nike

我正在尝试重现基于 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]] 为您完成所有工作。

安装了 RRcpp 的当前版本后,创建一个名为 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')

如果您按照说明安装 RR-tools 并设置 PATH 变量(如果在 Windows 上),那应该可行正确。

关于c++ - cxxfunction 错误消息,内联 R 包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25491717/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com