RcppArmadillo + bigmemory 崩溃 Windows RStudio(但没有其他 GUI + OS.type)

RcppArmadillo + bigmemory crashes Windows RStudio (but no other GUI + OS.type)

我正在处理 R 包,bigKRLS. bigKRLS 正在处理 Windows RGui,但在 Windows RStudio 上遇到致命错误。一些细节...

Windows RGui 工作但 Windows RStudio 遇到致命错误;使用 R 3.3.0、3.3.1、3.3.3 在四台不同的机器上确认; best practices recommended by the Coatless Professor; RStudio 1.0.136; Windows 7 and 8. Presently, bigKRLS 之后的 RTools 3.3 和 3.4 在 RStudio 上适用于 Mac OS X Yosemite 和 Ubuntu 14.04 没有问题。

bigKRLS depends on bigmemory, Rcpp, RcppArmadillo, and snow (but the problem pre-dates the recent addition of snow,出于测试目的,可以通过设置 bigKRLS(..., Ncores = 1)) 将其禁用。

devtools::install_github('rdrr1990/bigKRLS')
library(bigKRLS)
vignette("bigKRLS_basics")

set.seed(2017)
X <- matrix(runif(60), ncol=3)
y <- X %*% 3:1 + rnorm(20)
out <- bigKRLS(y, X)
summary(out)

上面的代码产生的模型估计从 R2 = 0.663 开始(我们当然在其他平台上估计了很多更复杂的模型)。

Windows RStudio 在没有警告的情况下加载 library(bigKRLS)bigKRLS() 输出它已成功清理数据。除此之外,这意味着 yX 现在是 big.matrix objects。然后第一个 "real" 步骤:bigKRLS() 调用 bGaussKernel(),这是会话在两分钟左右后中止的地方。不过bGaussKernel()好像也没什么问题。 bGaussKernel() 运行 如果在一秒钟内从命令行调用就可以了。事实上,如果您初始化 bigKRLS() 需要的每个变量,您可以 运行 在 Windows RStudio 中 运行 它的所有代码。

目前,package detects when Windows RStudio is being used and safely exits the function,将用户引导至 RGui。任何关于更好的解决方法的建议将不胜感激!

首先,Windows上的问题与编译器无关。如果您设法正确安装了 RTools,那么使用 RGUI 一切都会顺利进行。相反,您遇到的问题似乎与 RStudio 在其应用程序中使用 Boost 不小心污染了对 BH package in the rsession process. RStudio, more so @kevinushey, recently addressed this issue by creating a custom build of Boost for RStudio that lives within rstudio_boost. The details and solution of this error can be found in more depth at https://github.com/rstudio/rstudio/pull/1061.

提供的 boost 命名空间的调用有关

长话短说,如果确实如此,只需检查 RStudio 版本是否为 >=1.1.129 即可。为此,您首先需要获得 RStudio daily version. With this in hand, we can reference the solution that @DirkEddelbuettel derived for his fabulous anytime package that was running into this issue. Specifically, to overcome this, he has added a short isRStudio() function on package load and calls the function each time before handing data off into C++.

@DirkEddelbuettel 使用的 isRStudio() function 为:

isRStudio <- if (Sys.getenv("RSTUDIO", unset="0") == "1" &&
                     exists("RStudio.Version") &&
                     ## the following is evil but keeps R CMD check off our back
                     eval(parse(text=paste("RStudio.Version()$Version",
                                           ">=", "\"1.1.129\"")))) TRUE else FALSE

注意:使用eval(parse(text=...))是为了避免运行进入包检查问题,例如...

.onLoad: no visible global function definition for ‘RStudio.Version’
Undefined global functions or variables:
    RStudio.Version