【问题标题】:Fatal Error while using Rcpp in RStudio on Windows在 Windows 上的 RStudio 中使用 Rcpp 时出现致命错误
【发布时间】:2015-12-18 07:41:35
【问题描述】:

我正在尝试在 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 运行的任何代码都会发生同样的“致命错误”。

【问题讨论】:

  • 您安装了哪个版本的 Rtools?您使用的是哪个 Rcpp 版本?
  • RTools 版本为 33,Rcpp 版本为 0.12.2
  • 我的建议是使用 Rtools32。 Rtools 33 不稳定。

标签: r windows rcpp


【解决方案1】:

尝试在本地重建,从 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 的工作方式相同。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-29
    • 2022-11-09
    • 2017-09-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多