feedback from posit.cloud users with experience on rstan
package is welcomed.
I am trying to use rstan on an RStudio Cloud session. The install.packages("rstan")
worked without error, reading the library also.
but following this toy example it returned the error below
options(mc.cores = parallel::detectCores())
rstan_options(auto_write = TRUE)
x=rnorm(1000,5,1)
my_data=list(N=1000,x~x)
stancode = 'data{ int N; real x[N];} parameters{real mu;real sigma;}
model{ x ~ normal(mu,sigma);}'
fit = stan(model_code = stancode,data=my_data)
it returns this error
Error in compileCode(f, code, language = language, verbose = verbose) :
/cloud/lib/x86_64-pc-linux-gnu-library/4.2/RcppEigen/include/Eigen/src/Core/DenseCoeffsBase.h:55:30: warning: ignoring attributes on template argument ‘Eigen::internal::packet_traits<double>::type’ {aka ‘__vector(2) double’} [-Wignored-attributes] 55 | >::type PacketReturnType; | ^~~~~~~~~~~~~~~~g++: fatal error: Killed signal terminated program cc1pluscompilation terminated.make: *** [/opt/R/4.2.2/lib/R/etc/Makeconf:178: file189644bbcfc.o] Error 1
Error in sink(type = "output") : invalid connection``
My session info :
R version 4.2.2 (2022-10-31)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04.5 LTS
Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/atlas/libblas.so.3.10.3
LAPACK: /usr/lib/x86_64-linux-gnu/atlas/liblapack.so.3.10.3
locale:
[1] LC_CTYPE=C.UTF-8 LC_NUMERIC=C LC_TIME=C.UTF-8 LC_COLLATE=C.UTF-8 LC_MONETARY=C.UTF-8 LC_MESSAGES=C.UTF-8
[7] LC_PAPER=C.UTF-8 LC_NAME=C LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=C.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] rstan_2.21.8 ggplot2_3.4.1 StanHeaders_2.21.0-7
loaded via a namespace (and not attached):
[1] Rcpp_1.0.10 pillar_1.8.1 compiler_4.2.2 prettyunits_1.1.1 tools_4.2.2 digest_0.6.31 pkgbuild_1.4.0
[8] evaluate_0.20 lifecycle_1.0.3 tibble_3.1.8 gtable_0.3.1 pkgconfig_2.0.3 rlang_1.0.6 cli_3.6.0
[15] rstudioapi_0.14 yaml_2.3.7 parallel_4.2.2 xfun_0.37 loo_2.5.1 fastmap_1.1.0 gridExtra_2.3
[22] withr_2.5.0 dplyr_1.1.0 knitr_1.42 generics_0.1.3 vctrs_0.5.2 stats4_4.2.2 grid_4.2.2
[29] tidyselect_1.2.0 glue_1.6.2 inline_0.3.19 R6_2.5.1 processx_3.8.0 fansi_1.0.4 rmarkdown_2.20
[36] callr_3.7.3 magrittr_2.0.3 htmltools_0.5.4 codetools_0.2-18 matrixStats_0.63.0 scales_1.2.1 ps_1.7.2
[43] colorspace_2.1-0 utf8_1.2.3 RcppParallel_5.1.6 munsell_0.5.0 crayon_1.5.2
Compiling C++ code needs quite a bit of memory. You can see the RAM meter in the upper right hand corner going red before the process is being killed.
If you klick on the RAM meter, you get to the "Resources" tab where you can change the amount of RAM. Using 4 GB of RAM seems to be enough for your example.
BTW,
parallel::detectCores()
does not work well in cases like this. Better useparallelly::availableCores()
, which also takes into account limitations imposed by croups. You can change the number of available CPUs in the "Resources" tab.