Stan_model compilation errors on Windows 7 SP1

Dear all

I have started to use rstan for the first time now. It runs quite smoothly on my rather old Macbook with macOS High Sierra now. However, I’d really like to get it running on my Windows 7 PC and I have run into trouble.

After several fresh installations of R, RStudio, and rstan, I still get a compilation error for the 8schools example.

Shortly put,

stan_model(file = ‘8schools.stan’)

produces the following error (copy-pasted from RStudio’s console):

Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! sh: -c: line 0: syntax error near unexpected token (' sh: -c: line 0: C:/RBuildTools/3.5/mingw_64/bin/g++ -std=gnu++11 -I"D:/PROGRA~1/R-36~1.2/include" -DNDEBUG -I"D:/Program Files (x86)/R-3.6.2/library/Rcpp/include/" -I"D:/Program Files (x86)/R-3.6.2/library/RcppEigen/include/" -I"D:/Program Files (x86)/R-3.6.2/library/RcppEigen/include/unsupported" -I"D:/Program Files (x86)/R-3.6.2/library/BH/include" -I"D:/Program Files (x86)/R-3.6.2/library/StanHeaders/include/src/" -I"D:/Program Files (x86)/R-3.6.2/library/StanHeaders/include/" -I"D:/Program Files (x86)/R-3.6.2/library/rstan/include" -DEIGEN_NO_DEBUG -D_REENTRANT -DBOOST_DISABLE_ASSERTS -DBOOST_PENDING_INTEGER_LOG2_HPP -include stan/math/prim/mat/fun/Eigen.hpp -std=c++1y -march=core2 -include D:/Program Files (x86)/R-3.6.2/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp -I D:/Program Files (x86)/R-3.6.2/library/StanHeaders/include -I D:/
In addition: Warning message:
In system(cmd, intern = !verbose) :
running command ‘D:/PROGRA~1/R-36~1.2/bin/x64/R CMD SHLIB file248812547402.cpp 2> file248812547402.cpp.err.txt’ had status 1
Error in sink(type = “output”) : invalid connection

The problem seems to have something to do with properly escaping certain characters. But I have no clue where to begin solving the problem.

Some other posts here seem to be related, but I did not find a solution there.

CompileCode error after installation in Win 10

Error in compileCode(f, code, language = language, verbose = verbose) : Compilation ERROR, function(s)/method(s) not created!

The C++ toolchain test succeeds.

Operating system: Windows 7 Ultimate SP1
R version: 3.6.2 (2019-12-12) – “Dark and Stormy Night”
R platform: x86_64-w64-mingw32/x64 (64-bit)
RStudio version: 1.2.5033

Output of ‘writeLines(readLines(file.path(Sys.getenv(“HOME”), “.R/Makevars”)))’ is:

writeLines(readLines(file.path(Sys.getenv(“HOME”), “.R\Makevars”)))
Error in file(con, “r”) : cannot open the connection
In addition: Warning message:
In file(con, “r”) :
cannot open file ‘C:\Users\Frosty\Documents/.R\Makevars’: No such file or directory

But with manual specification of the path, output of ‘writeLines(readLines(file.path(“C:\Users\Frosty\Documents\.R\Makevars.win”)))’ is:

CXX14FLAGS=-O3 -march=native -mtune=native
CXX11FLAGS=-O3 -march=corei7 -mtune=corei7

CXX14FLAGS=-O3 -march=native -mtune=native
CXX11FLAGS=-O3 -march=corei7 -mtune=corei7

CXX14FLAGS=-O3 -march=native -mtune=native\nCXX11FLAGS=-O3 -march=corei7 -mtune=corei7
CXX14FLAGS=-O3 -march=native -mtune=native
CXX11FLAGS=-O3 -march=corei7 -mtune=corei7

Output of devtools::session_info("rstan"):

  • Session info -----------------------------------------------------------
    setting value
    version R version 3.6.2 (2019-12-12)
    os Windows 7 x64 SP 1
    system x86_64, mingw32
    ui RStudio
    language (EN)
    collate German_Germany.1252
    ctype German_Germany.1252
    tz Europe/Berlin
    date 2020-02-24
  • Packages ---------------------------------------------------------------
    ! package * version date lib source
    assertthat 0.2.1 2019-03-21 [1] CRAN (R 3.6.2)
    backports 1.1.5 2019-10-02 [1] CRAN (R 3.6.1)
    BH 1.72.0-3 2020-01-08 [1] CRAN (R 3.6.2)
    callr 3.4.2 2020-02-12 [1] CRAN (R 3.6.2)
    checkmate 2.0.0 2020-02-06 [1] CRAN (R 3.6.2)
    cli 2.0.1 2020-01-08 [1] CRAN (R 3.6.2)
    colorspace 1.4-1 2019-03-18 [1] CRAN (R 3.6.1)
    crayon 1.3.4 2017-09-16 [1] CRAN (R 3.6.2)
    desc 1.2.0 2018-05-01 [1] CRAN (R 3.6.2)
    digest 0.6.24 2020-02-12 [1] CRAN (R 3.6.2)
    ellipsis 0.3.0 2019-09-20 [1] CRAN (R 3.6.2)
    fansi 0.4.1 2020-01-08 [1] CRAN (R 3.6.2)
    farver 2.0.3 2020-01-16 [1] CRAN (R 3.6.2)
    ggplot2 * 3.2.1 2019-08-10 [1] CRAN (R 3.6.2)
    glue 1.3.1 2019-03-12 [1] CRAN (R 3.6.2)
    gridExtra 2.3 2017-09-09 [1] CRAN (R 3.6.2)
    gtable 0.3.0 2019-03-25 [1] CRAN (R 3.6.2)
    inline 0.3.15 2018-05-18 [1] CRAN (R 3.6.2)
    labeling 0.3 2014-08-23 [1] CRAN (R 3.6.0)
    D lattice 0.20-38 2018-11-04 [1] CRAN (R 3.6.2)
    lazyeval 0.2.2 2019-03-15 [1] CRAN (R 3.6.2)
    lifecycle 0.1.0 2019-08-01 [1] CRAN (R 3.6.2)
    loo 2.2.0 2019-12-19 [1] CRAN (R 3.6.2)
    magrittr 1.5 2014-11-22 [1] CRAN (R 3.6.2)
    MASS 7.3-51.4 2019-03-31 [1] CRAN (R 3.6.2)
    Matrix 1.2-18 2019-11-27 [1] CRAN (R 3.6.2)
    matrixStats 0.55.0 2019-09-07 [1] CRAN (R 3.6.2)
    mgcv 1.8-31 2019-11-09 [1] CRAN (R 3.6.2)
    munsell 0.5.0 2018-06-12 [1] CRAN (R 3.6.2)
    nlme 3.1-142 2019-11-07 [1] CRAN (R 3.6.2)
    pillar 1.4.3 2019-12-20 [1] CRAN (R 3.6.2)
    pkgbuild 1.0.6 2019-10-09 [1] CRAN (R 3.6.2)
    pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 3.6.2)
    plyr 1.8.5 2019-12-10 [1] CRAN (R 3.6.2)
    prettyunits 1.1.1 2020-01-24 [1] CRAN (R 3.6.2)
    processx 3.4.2 2020-02-09 [1] CRAN (R 3.6.2)
    ps 1.3.2 2020-02-13 [1] CRAN (R 3.6.2)
    R6 2.4.1 2019-11-12 [1] CRAN (R 3.6.2)
    RColorBrewer 1.1-2 2014-12-07 [1] CRAN (R 3.6.0)
    Rcpp 1.0.3 2019-11-08 [1] CRAN (R 3.6.2)
    RcppEigen 0.3.3.7.0 2019-11-16 [1] CRAN (R 3.6.2)
    reshape2 1.4.3 2017-12-11 [1] CRAN (R 3.6.2)
    rlang 0.4.4 2020-01-28 [1] CRAN (R 3.6.2)
    rprojroot 1.3-2 2018-01-03 [1] CRAN (R 3.6.2)
    rstan * 2.19.3 2020-02-11 [1] CRAN (R 3.6.2)
    scales 1.1.0 2019-11-18 [1] CRAN (R 3.6.2)
    StanHeaders * 2.21.0-1 2020-01-19 [1] CRAN (R 3.6.2)
    stringi 1.4.6 2020-02-17 [1] CRAN (R 3.6.2)
    stringr 1.4.0 2019-02-10 [1] CRAN (R 3.6.2)
    tibble 2.1.3 2019-06-06 [1] CRAN (R 3.6.2)
    utf8 1.1.4 2018-05-24 [1] CRAN (R 3.6.2)
    vctrs 0.2.2 2020-01-24 [1] CRAN (R 3.6.2)
    viridisLite 0.3.0 2018-02-01 [1] CRAN (R 3.6.2)
    withr 2.1.2 2018-03-15 [1] CRAN (R 3.6.2)

[1] D:/Program Files (x86)/R-3.6.2/library

D – DLL MD5 mismatch, broken installation.

Where the last part confuses me especially, because everything else works fine.

Again, I am new to rstan and hope somebody can help me. It’s hopefully a simple fix that I have just overlooked. But short of setting up the entire system (including Windows) from scratch, I am stuck right now.

Cheerio!

(edited for the typos I found)

I think the first thing to do is to get your StanHeaders and rstan versions back in sync (on 2.19.x) with

remove.packages("StanHeaders")
file.remove(".RData")
# restart R
install.packages("StanHeaders")

But also your ~/.R/Makevars.win file looks messed up. I would just delete it with

file.remove("~/.R/Makevars.win")

and then run


again.

Thanks @bgoodri. I’ll be back with an update as soon as I find the time to do what you propose.

Well, so far no luck, unfortunately. I did a fresh installation of everything and also followed your approach, Ben (@bgoodri). No luck. I receive the same error message regarding the problems to compile the model.

In addition, I noticed the following weird behavior. After installing the RTools and passing the pkgbuild::has_build_tools(debug = TRUE) check, stan(file = ‘8schools.stan’, data = schools_dat) and stan_model(file = ‘8schools.stan’) ask me to install RTools again. This results on temporary versions of RTools.tmp to clutter up my Temp folder.

But if no easy fix comes to mind, I’ll stop it here. It’s time to move to a new OS anyway.

The error message should at least be somewhat different. Can you post the part starting with g++ again?

Hi Ben.

Thanks for following up. I am travelling and I am not working on the pc. I’ll be back on Saturday, will perform another sweep and then post the error message again.

Hi @bgoodri, I am back from my trip.

I swiped the system clean again for a fresh start. Everything worked flawlessly until the call to

fit <- stan(file = “8schools.stan”, data = schools_dat).

And this is when I get this error message (again).

Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! sh: -c: line 0: syntax error near unexpected token (' sh: -c: line 0: C:/Rtools/mingw_64/bin/g++ -std=gnu++11 -I"D:/PROGRA~1/R/R-36~1.2/include" -DNDEBUG -I"D:/Program Files (x86)/R/R-3.6.2/library/Rcpp/include/" -I"D:/Program Files (x86)/R/R-3.6.2/library/RcppEigen/include/" -I"D:/Program Files (x86)/R/R-3.6.2/library/RcppEigen/include/unsupported" -I"D:/Program Files (x86)/R/R-3.6.2/library/BH/include" -I"D:/Program Files (x86)/R/R-3.6.2/library/StanHeaders/include/src/" -I"D:/Program Files (x86)/R/R-3.6.2/library/StanHeaders/include/" -I"D:/Program Files (x86)/R/R-3.6.2/library/rstan/include" -DEIGEN_NO_DEBUG -D_REENTRANT -DBOOST_DISABLE_ASSERTS -DBOOST_PENDING_INTEGER_LOG2_HPP -include stan/math/prim/mat/fun/Eigen.hpp -std=c++1y -march=core2 -include D:/Program Files (x86)/R/R-3.6.2/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp -I D:/Program Files (x86)/R/R-3.6.2/library/StanHeaders/inc
In addition: Warning message:
In system(cmd, intern = !verbose) :
running command ‘D:/PROGRA~1/R/R-36~1.2/bin/x64/R CMD SHLIB file20181f8871b5.cpp 2> file20181f8871b5.cpp.err.txt’ had status 1
Error in sink(type = “output”) : invalid connection

Then I went on to remove StanHeaders again as per your instructions. After reinstall, the package versions are:

packageVersion(“rstan”)
[1] ‘2.19.3’
packageVersion(“StanHeaders”)
[1] ‘2.21.0.1’

I went on with your suggestions, removed Makevars.win and also went through the steps at the suggested link.

The good news is that I am not constantly asked anymore, to install RTools again. This is the upside.

Alas! No ultimate success. Here is the final error message that I received after runnding fit <- stan(file = “8schools.stan”, data = schools_dat) again.

Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! sh: -c: line 0: syntax error near unexpected token (' sh: -c: line 0: C:/Rtools/mingw_64/bin/g++ -std=gnu++11 -I"D:/PROGRA~1/R/R-36~1.2/include" -DNDEBUG -I"D:/Program Files (x86)/R/R-3.6.2/library/Rcpp/include/" -I"D:/Program Files (x86)/R/R-3.6.2/library/RcppEigen/include/" -I"D:/Program Files (x86)/R/R-3.6.2/library/RcppEigen/include/unsupported" -I"D:/Program Files (x86)/R/R-3.6.2/library/BH/include" -I"D:/Program Files (x86)/R/R-3.6.2/library/StanHeaders/include/src/" -I"D:/Program Files (x86)/R/R-3.6.2/library/StanHeaders/include/" -I"D:/Program Files (x86)/R/R-3.6.2/library/rstan/include" -DEIGEN_NO_DEBUG -D_REENTRANT -DBOOST_DISABLE_ASSERTS -DBOOST_PENDING_INTEGER_LOG2_HPP -include stan/math/prim/mat/fun/Eigen.hpp -std=c++1y -march=core2 -include D:/Program Files (x86)/R/R-3.6.2/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp -I D:/Program Files (x86)/R/R-3.6.2/library/StanHeaders/inc
In addition: Warning message:
In system(cmd, intern = !verbose) :
running command ‘D:/PROGRA~1/R/R-36~1.2/bin/x64/R CMD SHLIB file1aa86c7f3347.cpp 2> file1aa86c7f3347.cpp.err.txt’ had status 1
Error in sink(type = “output”) : invalid connection

This looks just the same again.

I am about to just move to a new OS anyway. Maybe this solves the issue. ;)

packageVersion(“StanHeaders”)
[1] ‘2.21.0.1’

It looks like the StanHeaders version is still ahead of the rstan version. Can you try:

install.packages(“StanHeaders”, type = "source")

Andrew and Ben

This works. I don’t know why I assumed that, certainly, StanHeaders must be “downward” compatible. Silly.

Thanks so much for your patience with this problem. Now I can finally run this on my home/office PC while travelling and using my laptop for other stuff. That helps a lot!

Cheerio!