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

我们两清 提交于 2019-12-24 00:57:10

问题


I'm working on an R package, bigKRLS. bigKRLS works on Windows RGui but encounters a fatal error on Windows RStudio. Some details...

Windows RGui works but Windows RStudio encounters a fatal error; confirmed on four different machines using R 3.3.0, 3.3.1, 3.3.3; RTools 3.3 and 3.4 following the best practices recommended by the Coatless Professor; RStudio 1.0.136; Windows 7 and 8. Presently, bigKRLS works on RStudio for Mac OS X Yosemite and Ubuntu 14.04 without issue.

bigKRLS depends on bigmemory, Rcpp, RcppArmadillo, and snow (but the problem pre-dates the recent addition of snow, which can be disabled for testing purposes by setting 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)

The code above yields model estimates started with R2 = 0.663 (we've of course estimated lots more complicated models on other platforms).

Windows RStudio loads library(bigKRLS) without warning; bigKRLS() outputs that it's cleaned the data successfully. Among other things, that means y and X are now big.matrix objects. Then the first "real" step: bigKRLS() calls bGaussKernel(), which is where the session aborts after two minutes or so. But there doesn't seem to be anything wrong with bGaussKernel(). bGaussKernel() runs just fine if called from the command line in under a second. In fact, if you initialize each variable that bigKRLS() requires, you can run all of its code in Windows RStudio.

Currently, the package detects when Windows RStudio is being used and safely exits the function, directing users instead to RGui. Any suggestions as to a better a workaround would be greatly appreciated!


回答1:


First, the problem on Windows is not related to the compiler. If you managed to install RTools correctly, then everything is going well for using RGUI. Instead, the problem that you are having seems to be with RStudio's use of Boost for their application that accidentally polluted calls to the boost namespace provided by the 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.

Long story short, if this is indeed the case, simply check if the RStudio version is >=1.1.129 will suffice. To do so, you will first need to get an 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++.

The isRStudio() function @DirkEddelbuettel uses is given as:

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

Note: The use of eval(parse(text=...)) is to avoid running into package check issues such as...

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


来源:https://stackoverflow.com/questions/43247649/rcpparmadillo-bigmemory-crashes-windows-rstudio-but-no-other-gui-os-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!