Error in if (grepl(pattern, makefile_txt[i])) { : argument is of length zero

I run the simple example rstan code. It works well on R 3.6.0 x64, but error occurs on R 3.6.0 i386.
The error message is as follows:

Compilation argument:
 C:/R/R-3.6.0/bin/i386/R CMD SHLIB file112414492dc0.cpp 2> file112414492dc0.cpp.err.txt 
c:/Rtools/mingw_32/bin/g++ -O2 -march=native -mtune=native  -I"C:/R/R-36~1.0/include" -DNDEBUG   -I"C:/R/R-3.6.0/library/Rcpp/include/"  -I"C:/R/R-3.6.0/library/RcppEigen/include/"  -I"C:/R/R-3.6.0/library/RcppEigen/include/unsupported"  -I"C:/R/R-3.6.0/library/BH/include" -I"C:/R/R-3.6.0/library/StanHeaders/include/src/"  -I"C:/R/R-3.6.0/library/StanHeaders/include/"  -I"C:/R/R-3.6.0/library/rstan/include" -DEIGEN_NO_DEBUG  -DBOOST_DISABLE_ASSERTS -std=c++1y    -march=core2     -O3 -march=native -mtune=native -fPIC -c file112414492dc0.cpp -o file112414492dc0.o
c:/Rtools/mingw_32/bin/g++ -O2 -march=native -mtune=native -shared -s -static-libgcc -o file112414492dc0.dll tmp.def file112414492dc0.o -LC:/R/R-3.6.0/library/StanHeaders/libs/i386 -lStanHeaders -LC:/R/R-36~1.0/bin/i386 -lR
file112414492dc0.cpp:1:0: warning: -fPIC ignored for target (all code is position independent)
 
 ^
In file included from C:/R/R-3.6.0/library/BH/include/boost/random/detail/integer_log2.hpp:19:0,
                 from C:/R/R-3.6.0/library/BH/include/boost/random/detail/int_float_pair.hpp:26,
                 from C:/R/R-3.6.0/library/BH/include/boost/random/exponential_distribution.hpp:27,
                 from C:/R/R-3.6.0/library/BH/include/boost/random/gamma_distribution.hpp:25,
                 from C:/R/R-3.6.0/library/StanHeaders/include/stan/math/prim/mat/prob/dirichlet_rng.hpp:5,
                 from C:/R/R-3.6.0/library/StanHeaders/include/stan/math/prim/mat.hpp:276,
                 from C:/R/R-3.6.0/library/StanHeaders/include/stan/math/rev/mat.hpp:12,
                 from C:/R/R-3.6.0/library/StanHeaders/include/stan/math.hpp:4,
                 from C:/R/R-3.6.0/library/StanHeaders/include/src/stan/model/model_header.hpp:4,
                 from file112414492dc0.cpp:8:
C:/R/R-3.6.0/library/BH/include/boost/pending/integer_log2.hpp:7:89: note: #pragma message: This header is deprecated. Use <boost/integer/integer_log2.hpp> instead.
 BOOST_HEADER_DEPRECATED("<boost/integer/integer_log2.hpp>");
                                                                                         ^
Error in if (grepl(pattern, makefile_txt[i])) { : 
  argument is of length zero

Here’s the example code I run.

library(rstan)
model_code <- 'parameters {real y;} model {y ~ normal(0,1);}'
fit <- stan(model_code=model_code, verbose = TRUE)  # this will take a minute
mean(extract(fit)$y)  # should be close to 0

Note that

  • Operating System : windows 10 x64
  • RStan Version: 2.18.2
  • Output of writeLines(readLines(file.path(Sys.getenv("HOME"), ".R/Makevars")))
CXX14FLAGS=-O3 -march=native -mtune=native -fPIC
CXX14 = g++ -m$(WIN) -std=c++1y
CXX14=$(BINPREF)g++ -O2 -march=native -mtune=native
  • Output of devtools::session_info("rstan")
- Session info ----------------------------------------------------------------------------------------------------------------------------------------------------------------
 setting  value                       
 version  R version 3.6.0 (2019-04-26)
 os       Windows 10 x64              
 system   i386, mingw32               
 ui       Rgui                        
 language (EN)                        
 collate  Korean_Korea.949            
 ctype    Korean_Korea.949            
 tz       Asia/Seoul                  
 date     2019-05-25                  

- Packages --------------------------------------------------------------------------------------------------------------------------------------------------------------------
 package      * version   date       lib source        
 assertthat     0.2.1     2019-03-21 [1] CRAN (R 3.6.0)
 backports      1.1.4     2019-04-10 [1] CRAN (R 3.6.0)
 BH             1.69.0-1  2019-01-07 [1] CRAN (R 3.6.0)
 callr          3.2.0     2019-03-15 [1] CRAN (R 3.6.0)
 checkmate      1.9.3     2019-05-03 [1] CRAN (R 3.6.0)
 cli            1.1.0     2019-03-19 [1] CRAN (R 3.6.0)
 colorspace     1.4-1     2019-03-18 [1] CRAN (R 3.6.0)
 crayon         1.3.4     2017-09-16 [1] CRAN (R 3.6.0)
 desc           1.2.0     2018-05-01 [1] CRAN (R 3.6.0)
 digest         0.6.19    2019-05-20 [1] CRAN (R 3.6.0)
 fansi          0.4.0     2018-10-05 [1] CRAN (R 3.6.0)
 ggplot2      * 3.1.1     2019-04-07 [1] CRAN (R 3.6.0)
 glue           1.3.1     2019-03-12 [1] CRAN (R 3.6.0)
 gridExtra      2.3       2017-09-09 [1] CRAN (R 3.6.0)
 gtable         0.3.0     2019-03-25 [1] CRAN (R 3.6.0)
 inline       * 0.3.15    2018-05-18 [1] CRAN (R 3.6.0)
 labeling       0.3       2014-08-23 [1] CRAN (R 3.6.0)
 lattice        0.20-38   2018-11-04 [1] CRAN (R 3.6.0)
 lazyeval       0.2.2     2019-03-15 [1] CRAN (R 3.6.0)
 loo            2.1.0     2019-03-13 [1] CRAN (R 3.6.0)
 magrittr       1.5       2014-11-22 [1] CRAN (R 3.6.0)
 MASS           7.3-51.4  2019-03-31 [1] CRAN (R 3.6.0)
 Matrix         1.2-17    2019-03-22 [1] CRAN (R 3.6.0)
 matrixStats    0.54.0    2018-07-23 [1] CRAN (R 3.6.0)
 mgcv           1.8-28    2019-03-21 [1] CRAN (R 3.6.0)
 munsell        0.5.0     2018-06-12 [1] CRAN (R 3.6.0)
 nlme           3.1-139   2019-04-09 [1] CRAN (R 3.6.0)
 pillar         1.4.0     2019-05-11 [1] CRAN (R 3.6.0)
 pkgbuild       1.0.3     2019-03-20 [1] CRAN (R 3.6.0)
 pkgconfig      2.0.2     2018-08-16 [1] CRAN (R 3.6.0)
 plyr           1.8.4     2016-06-08 [1] CRAN (R 3.6.0)
 prettyunits    1.0.2     2015-07-13 [1] CRAN (R 3.6.0)
 processx       3.3.1     2019-05-08 [1] CRAN (R 3.6.0)
 ps             1.3.0     2018-12-21 [1] CRAN (R 3.6.0)
 R6             2.4.0     2019-02-14 [1] CRAN (R 3.6.0)
 RColorBrewer   1.1-2     2014-12-07 [1] CRAN (R 3.6.0)
 Rcpp           1.0.1     2019-03-17 [1] CRAN (R 3.6.0)
 RcppEigen      0.3.3.5.0 2018-11-24 [1] CRAN (R 3.6.0)
 reshape2       1.4.3     2017-12-11 [1] CRAN (R 3.6.0)
 rlang          0.3.4     2019-04-07 [1] CRAN (R 3.6.0)
 rprojroot      1.3-2     2018-01-03 [1] CRAN (R 3.6.0)
 rstan        * 2.18.2    2018-11-07 [1] CRAN (R 3.6.0)
 scales         1.0.0     2018-08-09 [1] CRAN (R 3.6.0)
 StanHeaders  * 2.18.1    2019-01-28 [1] CRAN (R 3.6.0)
 stringi        1.4.3     2019-03-12 [1] CRAN (R 3.6.0)
 stringr        1.4.0     2019-02-10 [1] CRAN (R 3.6.0)
 tibble         2.1.1     2019-03-16 [1] CRAN (R 3.6.0)
 utf8           1.1.4     2018-05-24 [1] CRAN (R 3.6.0)
 vctrs          0.1.0     2018-11-29 [1] CRAN (R 3.6.0)
 viridisLite    0.3.0     2018-02-01 [1] CRAN (R 3.6.0)
 withr          2.1.2     2018-03-15 [1] CRAN (R 3.6.0)
 zeallot        0.1.0     2018-01-28 [1] CRAN (R 3.6.0)

[1] C:/R/R-3.6.0/library

There might be a fix for this in the Github version of Rstan: Error in if (grepl(pattern, makefile_txt[i]))

Depending on how much of a showstopper this is, you could try installing from Github as described here: https://github.com/stan-dev/rstan/wiki/Installing-RStan-from-source-on-Windows . I don’t see the issue (https://github.com/stan-dev/rstan/issues/634) marked as fixed though, so your mileage may vary there.

@Slawek_Smyl reported that this wasn’t an issue with the Ubuntu version, if you have access to an Ubuntu install.

Thanks for comment @bbbales2.
I tried installing from Github by remotes::install_github("stan-dev/rstan", ref = "develop", subdir = "rstan/rstan", build_opts = ""), but error occurs.
The error message is:

Error in (function (command = NULL, args = character(), error_on_status = TRUE,  : 
  System command error
In addition: Warning message:
In utils::untar(tarfile, ...) :
  ‘tar.exe -xf "C:\Users\NHKIM1~1\AppData\Local\Temp\RtmpM5YbIC\file3dd474be7b61.tar.gz" -C "C:/Users/NHKIM1~1/AppData/Local/Temp/RtmpM5YbIC/remotes3dd45bae1b7c"’ returned error code 2

Uh oh, I don’t know what to do from this point. I’m using Ubuntu here. The fact that it works in x64 and fails with i386 is weird, but it looks like the line of code in question did get changed recently: https://github.com/stan-dev/rstan/commit/daade233f0f91a968345d3aec84779eab19bf88b#diff-c8af6d5a55d29ad6cf5bcf2573a43bb1 , so installing from Github seems like a good way to go.

@bgoodri do you have any idea what that install error means?

I don’t know why it fails in weird circumstances, but installing from GitHub should be fine.