Rstantool in R 4.0.X "Error in (function (command = NULL, args = character(), error_on_status = TRUE"

Problem overview

rstantools stopped working for me when upgraded to R 4.0.X (both 0 and 2). and I’m not sure why. It stopped on both my native Windows R, WSL Ubuntu R, and in a Rocker Image asachet/rocker-stan docker image running RStudio. However, when I run asachet/rocker-stan:3.6.1, rstantools works for me.

Solutions I have tried and reproducible example

I have tried going through the simple example vignette and I get stuck at the same point in all three systems. I have looked through the Discourse Forum (e.g., here, here, and here). The last post I found with this issue was about a month ago and was using R 3.6.1 on Windows. I found another post where someone noted roxygen2 usually breaks about once a month. Is this monthly break for roxygen2?

Specifically, when I get to this part of vignette

try(roxygen2::roxygenize(load_code = sourceDir), silent = TRUE)
pkgbuild::compile_dll()
roxygen2::roxygenize()

I get an error:

Error in (function (command = NULL, args = character(), error_on_status = TRUE,  : 
  System command 'R' failed, exit status: 1, stdout + stderr (last 10 lines):
E> /usr/local/lib/R/site-library/StanHeaders/include/src/stan/mcmc/hmc/hamiltonians/dense_e_metric.hpp:23:56:   required from ‘double stan::mcmc::dense_e_metric<Model, BaseRNG>::T(stan::mcmc::dense_e_point&) [with Model = model_lm_namespace::model_lm; BaseRNG = boost::random::additive_combine_engine<boost::random::linear_congruential_engine<unsigned int, 40014, 0, 2147483563>, boost::random::linear_congruential_engine<unsigned int, 40692, 0, 2147483399> >]’
E> /usr/local/lib/R/site-library/StanHeaders/include/src/stan/mcmc/hmc/hamiltonians/dense_e_metric.hpp:22:10:   required from here
E> /usr/local/lib/R/site-library/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]
E> g++ -std=gn

My SessionInfo() is posted at the end of this post.

Specific questions

  • How do I get the minimum example vignette working with R 4.0.X? My ideal solution would be a Docker Image that works. But, I what I need to know is what version of rstantools I should be using (e.g., GitHub vs CRAN)?
  • I there some place that tells me the above answer that I am missing? If so, how do I find it in the future?

Last, thank you (the Stan Community) for your help. I understand some packages like roxygen2 change and break your tools. Also, thank you for your work getting RStan to work with RStudio so that I can run RStan with Rocker!!!

SessionInfo()

R version 4.0.2 (2020-06-22)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 20.04 LTS

Matrix products: default
BLAS/LAPACK: /usr/lib/x86_64-linux-gnu/openblas-openmp/libopenblasp-r0.3.8.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=C             
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods  
[7] base     

loaded via a namespace (and not attached):
 [1] rstan_2.19.3         RcppEigen_0.3.3.7.0  tidyselect_1.1.0    
 [4] xfun_0.15            purrr_0.3.4          lattice_0.20-41     
 [7] testthat_2.3.2       colorspace_1.4-1     vctrs_0.3.1         
[10] generics_0.0.2       stats4_4.0.2         loo_2.2.0           
[13] rlang_0.4.6          pkgbuild_1.0.8       pillar_1.4.4        
[16] glue_1.4.1           withr_2.2.0          matrixStats_0.56.0  
[19] lifecycle_0.2.0      stringr_1.4.0        munsell_0.5.0       
[22] commonmark_1.7       gtable_0.3.0         inline_0.3.15       
[25] knitr_1.29           callr_3.4.3          ps_1.3.3            
[28] parallel_4.0.2       fansi_0.4.1          Rcpp_1.0.4.6        
[31] scales_1.1.1         backports_1.1.8      pkgload_1.1.0       
[34] desc_1.2.0           RcppParallel_5.0.2   StanHeaders_2.21.0-5
[37] gridExtra_2.3        ggplot2_3.3.2        packrat_0.5.0       
[40] digest_0.6.25        stringi_1.4.6        processx_3.4.2      
[43] dplyr_1.0.0          grid_4.0.2           rprojroot_1.3-2     
[46] BH_1.72.0-3          cli_2.0.2            tools_4.0.2         
[49] magrittr_1.5         tibble_3.0.1         crayon_1.3.4        
[52] pkgconfig_2.0.3      ellipsis_0.3.1       Matrix_1.2-18       
[55] xml2_1.3.2           prettyunits_1.1.1    assertthat_0.2.1    
[58] roxygen2_7.1.1       rstudioapi_0.11      R6_2.4.1            
[61] compiler_4.0.2      

Using the rstantools from CRAN is fine. What is the error when you do

example(source)
roxygen2::roxygenize(load_code = sourceDir)

?

1 Like
> roxygen2::roxygenize(load_code = sourceDir)
Error: Can't extract an environment from a call
Run `rlang::last_error()` to see where the error occurred.

Which then shows me :

> rlang::last_error()
<error/rlang_error>
Can't extract an environment from a call
Backtrace:
 1. roxygen2::roxygenize(load_code = sourceDir)
 2. base::lapply(blocks, block_set_env, env = env)
 3. roxygen2:::FUN(X[[i]], ...)
 4. roxygen2:::block_find_object(block, env)
 5. roxygen2:::object_from_call(...)
 6. rlang::call_standardise(call, env)
 7. rlang::get_env(call, env)
Run `rlang::last_trace()` to see the full context.

Maybe

roxygen2::roxygenize(load_code = sourceDir, clean = TRUE)

?

> roxygen2::roxygenize(load_code = sourceDir, clean = TRUE)
Writing NAMESPACE
Error: Can't extract an environment from a call
Run `rlang::last_error()` to see where the error occurred.

What is

rlang::last_trace()

after

roxygen2::roxygenize(load_code = sourceDir, clean = TRUE)

?

It’s a nice-looking error message!

> roxygen2::roxygenize(load_code = sourceDir, clean = TRUE)
Writing NAMESPACE
Error: Can't extract an environment from a call
Run `rlang::last_error()` to see where the error occurred.
> rlang::last_trace()
<error/rlang_error>
Can't extract an environment from a call
Backtrace:
    █
 1. └─roxygen2::roxygenize(load_code = sourceDir, clean = TRUE)
 2.   └─base::lapply(blocks, block_set_env, env = env)
 3.     └─roxygen2:::FUN(X[[i]], ...)
 4.       └─roxygen2:::block_find_object(block, env)
 5.         └─roxygen2:::object_from_call(...)
 6.           └─rlang::call_standardise(call, env)
 7.             └─rlang::get_env(call, env)

Do you get this error outside the Docker image?

I’m getting a different error:

> roxygen2::roxygenize(load_code = sourceDir)
Error in inDL(x, as.logical(local), as.logical(now), ...) : 
  unable to load shared object 'C:/Users/rerickson/Documents/R/win-library/4.0/Rcpp/libs/x64/Rcpp.dll':
  LoadLibrary failure:  The specified procedure could not be found.

Looks like I have two problems. One with Windows and one with Docker. I don’t have local admin over my computer, so I’ll have to put in a request for IT to update R to 4.0.2 .

> sessionInfo()
R version 4.0.0 (2020-04-24)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 17763)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                           LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] rstantools_2.1.1

loaded via a namespace (and not attached):
[1] R6_2.4.1       magrittr_1.5   rlang_0.4.6    stringi_1.4.6  tools_4.0.0    stringr_1.4.0  compiler_4.0.0

OK. Don’t bother IT yet. I just wanted to see if the problems were Docker-specific.

1 Like

Thanks. Also, I tried in both RStudio and emacs/ess and got the same error.

What is the output of

dir(system.file("lib", package = "Rcpp"), recursive = TRUE, full.names = TRUE)

outside Docker?

Outside docker

> dir(system.file("lib", package = "Rcpp"), recursive = TRUE, full.names = TRUE)
character(0)

out of curiosity, @bgoodri do you use Docker and can you recreate my Docker problem?

I’ll try later

1 Like

As a solution with Docker, upgrading to R 4.0.2 made rstantools work for me. I also had to force an upgrade to all of my packages. Also, here’s a dockerfile that works for me (with R version 4.0.2 on 20 July 2020):

FROM rocker/verse

## Adapted from https://hub.docker.com/r/asachet/rocker-stan/dockerfile
## To strip down the rocker version
## and also write the install_rstan.R file inside of docker instead of
## copying it locally
RUN apt-get update \
	&& apt-get install -y --no-install-recommends \
	clang


## From https://github.com/stan-dev/rstan/wiki/Installing-RStan-on-Linux
RUN echo \
	'dotR <- file.path(Sys.getenv("HOME"), ".R")\n\
	if (!file.exists(dotR)) dir.create(dotR)\n\
	M <- file.path(dotR, "Makevars")\n\
	if (!file.exists(M)) file.create(M)\n\
	cat("\nCXX14FLAGS=-O3 -march=native -mtune=native -fPIC",\n\
	"CXX14=g++",\n\
	file = M, sep = "\n", append = TRUE)'\
	| cat >> install_rstan.R

RUN ["r", "install_rstan.R"]


# Install rstan
RUN install2.r --error --deps TRUE \
    rstan \
    && rm -rf /tmp/downloaded_packages/ /tmp/*.rds

# Installing the rest 
RUN install2.r -s --error \
	bayesplot \
	brms \
	coda \
	loo \
	projpred \
	rstanarm \
	rstantools \ 
	shinystan \
	tidybayes \
	ggthemes

RUN R -e "update.packages(repos = 'http://cran.us.r-project.org')"

I got the exact same error when I run either devtools::document() or devtools::load_all() or pkgbuild::compile_dll() for the package that I am developing which depends on rstan. However, I am developing inside an Apptainer container in a Linux environment. Does anyone have other suggestions on how to solve this issue please? I have tested the stan model files and there is no syntax error in them.

UPDATE: The same error came up in MacOS as well.

This is the .Last.error from kgbuild::compile_dll()

> .Last.error
<system_command_status_error/rlib_error_3_0/rlib_error/error>
Error in `(function (command = NULL, args = character(), error_on_status = TRUE, …`:
! System command 'R' failed
---
Exit status: 1
stdout & stderr: <printed>
---
Backtrace:
 1. pkgbuild::compile_dll()
 2. pkgbuild:::install_min(path, dest = install_dir, components = "libs", args = if (needs_clean(path)) "--preclean", …
 3. pkgbuild::rcmd_build_tools("INSTALL", c(path, paste("--library=", dest, …
 4. pkgbuild::with_build_tools({ …
 5. base::withCallingHandlers(callr::rcmd_safe(..., env = env, spinner = FALSE, …
 6. callr::rcmd_safe(..., env = env, spinner = FALSE, show = FALSE, …
 7. callr:::run_r(options)
 8. base::with(options, with_envvar(env, do.call(processx::run, c(list(bin, …
 9. base::with.default(options, with_envvar(env, do.call(processx::run, …
10. base::eval(substitute(expr), data, enclos = parent.frame())
11. base::eval(substitute(expr), data, enclos = parent.frame())
12. callr:::with_envvar(env, do.call(processx::run, c(list(bin, args = real_cmdargs, …
13. base::force(code)
14. base::do.call(processx::run, c(list(bin, args = real_cmdargs, stdout_line_callback = real_callback(stdout), …
15. (function (command = NULL, args = character(), error_on_status = TRUE, …
16. base::throw(new_process_error(res, call = sys.call(), echo = echo, …
17. | base::signalCondition(cond)
18. (function (e) …
19. asNamespace("callr")$err$throw(e)