繁体   English   中英

在Windows的RStudio中使用Rcpp时发生致命错误

[英]Fatal Error while using Rcpp in RStudio on Windows

我正在尝试在RStudio的Windows上使用Rcpp。 我有R版本3.2.3,并且已经安装了Rcpp软件包。 问题是我无法调用通过CPP代码定义的任何函数。 我尝试了以下操作(从在线示例中挑选)。

body <- '
NumericVector xx(x);
return wrap( std::accumulate( xx.begin(), xx.end(), 0.0));'
add <- cxxfunction(signature(x = "numeric"), body, plugin = "Rcpp")

这给出以下警告,但成功完成执行。

cygwin warning:
MS-DOS style path detected: C:/R/R-32~1.3/etc/x64/Makeconf
Preferred POSIX equivalent is: /cygdrive/c/R/R-32~1.3/etc/x64/Makeconf
CYGWIN environment variable option "nodosfilewarning" turns off this warning.
Consult the user's guide for more details about POSIX paths:
http://cygwin.com/cygwin-ug-net/using.html#using-pathnames

当我尝试使用上述功能时,

x <- 1
y <- 2
res <- add(c(x, y))

我收到以下错误:

R Session Aborted
R encountered a fatal error.
The session was terminated.

有什么建议么? 对于我使用Rcpp运行的任何代码,也会发生同样的“致命错误”。

尝试从Rcpp开始在本地重建。 这是有效的代码,并且可以正常工作(而且数百个单元测试的压力可能还不止于此)。 有时编译器或其他东西在您的控制下发生变化,并且这种情况发生了。 然后,使用备用构建系统很有用-例如,通过GitHub上的Travis,您可以免费获得Linux。

另外,了解Rcpp属性。 您的示例可以写成

R> library(Rcpp)
R> cppFunction("double adder(std::vector<double> x) { return std::accumulate(x.begin(), x.end(), 0.0); }")
R> adder(c(1,2))
[1] 3
R> 

这比较简单。 当然,与Rcpp::NumericVector方式相同。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM