Installing dev version rstan on Windows 10 with R3.6

I am trying to install the dev version of rstan because I want to fit ODE models with ts & t0 as parameters (available on stan 2.20, Var initial time and time vector for ODE solver by charlesm93 · Pull Request #2791 · stan-dev/stan · GitHub). My previous version of rstan was installed only a few months ago, and used an ealier version of stan. I have now managed to break something and cannot install/ run stan models successfully. The character limit in questions does not allow me to post the entire output from the install process, so I have only posted part of it, I can add more in the comments if requested.

  • Operating System: Windows 10 Education 1909
  • RStudio version: 1.2.5033
  • R version: R-3.6.3 (64bit)
  • RStan Version: Trying to install dev version
  • Output of writeLines(readLines(file.path(Sys.getenv("HOME"), ".R/Makevars")))

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<usernamewithspace>\Documents/.R/Makevars’: No such file or directory
writeLines(readLines(file.path(Sys.getenv(“HOME”), “.R/Makevars.win”)))
CXX14FLAGS=-O3 -march=corei7 -mtune=corei7
CXX14 = (BINPREF)g++ -m(WIN) -std=c++1y
CXX11FLAGS=-O3 -march=corei7 -mtune=corei7

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

devtools::session_info(“rstan”)

  • Session info -------------------------------------------------------------------
    setting value
    version R version 3.6.3 (2020-02-29)
    os Windows 10 x64
    system x86_64, mingw32
    ui RStudio
    language (EN)
    collate English_United Kingdom.1252
    ctype English_United Kingdom.1252
    tz Pacific/Auckland
    date 2020-04-04

  • Packages -----------------------------------------------------------------------
    ! package * version date lib source
    R rstan [?]

[1] C:/Users//Documents/R/win-library/3.6
[2] C:/Program Files/R/R-3.6.3/library

R – Package was removed from disk.

  • pkgbuild::has_build_tools(debug = TRUE)
    [1] TRUE

I’ve tried many different Makevars configurations from various googled help pages with no success. The error messages below are from the above Makevars file.

Note: I think I solved a few additional problems by doing the following before the instructions on the official install page.
.libPaths( c( “C:\RLibrary” , .libPaths() ) ) # old library path had spaces in it
write(“TMP = ‘C:\tmp’”, file=file.path(Sys.getenv(‘R_USER’), ‘.Renviron’)) # tmp path had spaces in it
Sys.setenv(“TAR” = “internal”) # it wasn’t finding the correct tar program

I tried the instructions on Home · stan-dev/rstan Wiki · GitHub and errors about changing the directory which were solved by removing " build_opts = “” " . This allows it to install, but it cannot run any stan code and gives warnings:

remotes::install_github(“stan-dev/rstan”, ref = “develop”, subdir = “rstan/rstan”)
Downloading GitHub repo stan-dev/rstan@develop
“C:\PROGRA~1\Git\cmd\git.exe” clone --depth 1 --no-hardlinks --recurse-submodules --branch develop GitHub - stan-dev/stan: Stan development repository. The master branch contains the current release. The develop branch contains the latest stable development. See the Developer Process Wiki for details. C:\tmp\RtmpAfCXup\remotes4dd8641d3d0c/stan-dev-rstan-fef82e9/rstan/rstan/…/…/StanHeaders/inst/include/upstream
“C:\PROGRA~1\Git\cmd\git.exe” clone --depth 1 --no-hardlinks --recurse-submodules --branch develop GitHub - stan-dev/math: The Stan Math Library is a C++ template library for automatic differentiation of any order using forward, reverse, and mixed modes. It includes a range of built-in functions for probabilistic modeling, linear algebra, and equation solving. C:\tmp\RtmpAfCXup\remotes4dd8641d3d0c/stan-dev-rstan-fef82e9/rstan/rstan/…/…/StanHeaders/inst/include/mathlib
√ checking for file ‘C:\tmp\RtmpAfCXup\remotes4dd8641d3d0c\stan-dev-rstan-fef82e9\rstan\rstan/DESCRIPTION’ (360ms)

  • preparing ‘rstan’: (3.7s)
    √ checking DESCRIPTION meta-information …
  • cleaning src
  • checking for LF line-endings in source and make files and shell scripts (647ms)
  • checking for empty or unneeded directories (3.2s)
  • looking to see if a ‘data/datalist’ file should be added
  • building ‘rstan_2.21.1.tar.gz’

Installing package into ‘C:/RLibrary’
(as ‘lib’ is unspecified)

  • installing source package ‘rstan’ …
    ** using staged installation
    ** libs

*** arch - i386
c:/Rtools/mingw_32/bin/g++ -m32 -std=c++1y -I"C:/PROGRA~1/R/R-36~1.3/include" -DNDEBUG -I"…/inst/include" -I"…/inst/include/boost_not_in_BH" -I"." -DBOOST_DISABLE_ASSERTS -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -DSTAN_THREADS -DRCPP_PARALLEL_USE_TBB=1 -I"C:/Users//Documents/R/win-library/3.6/Rcpp/include" -I"C:/Users//Documents/R/win-library/3.6/RcppEigen/include" -I"C:/Users//Documents/R/win-library/3.6/BH/include" -I"C:/RLibrary/StanHeaders/include" -I"C:/Users//Documents/R/win-library/3.6/RcppParallel/include" -DRCPP_PARALLEL_USE_TBB=1 -O3 -march=corei7 -mtune=corei7 -c sparse_extractors.cpp -o sparse_extractors.o
c:/Rtools/mingw_32/bin/g++ -m32 -std=c++1y -I"C:/PROGRA~1/R/R-36~1.3/include" -DNDEBUG -I"…/inst/include" -I"…/inst/include/boost_not_in_BH" -I"." -DBOOST_DISABLE_ASSERTS -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -DSTAN_THREADS -DRCPP_PARALLEL_USE_TBB=1 -I"C:/Users//Documents/R/win-library/3.6/Rcpp/include" -I"C:/Users//Documents/R/win-library/3.6/RcppEigen/include" -I"C:/Users//Documents/R/win-library/3.6/BH/include" -I"C:/RLibrary/StanHeaders/include" -I"C:/Users//Documents/R/win-library/3.6/RcppParallel/include" -DRCPP_PARALLEL_USE_TBB=1 -O3 -march=corei7 -mtune=corei7 -c misc.cpp -o misc.o
c:/Rtools/mingw_32/bin/g++ -m32 -std=c++1y -I"C:/PROGRA~1/R/R-36~1.3/include" -DNDEBUG -I"…/inst/include" -I"…/inst/include/boost_not_in_BH" -I"." -DBOOST_DISABLE_ASSERTS -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -DSTAN_THREADS -DRCPP_PARALLEL_USE_TBB=1 -

… lots of excluded output

LC:/Users/POPPYM~1/DOCUME~1/R/WIN-LI~1/3.6/RCPPPA~1/lib/x64 -ltbb -ltbbmalloc -LC:/PROGRA~1/R/R-36~1.3/bin/x64 -lR
c:/Rtools/mingw_64/bin/g++ -m64 -std=c++1y -I"C:/PROGRA~1/R/R-36~1.3/include" -DNDEBUG -I"…/inst/include" -I"…/inst/include/boost_not_in_BH" -I"." -DBOOST_DISABLE_ASSERTS -DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -DSTAN_THREADS -DRCPP_PARALLEL_USE_TBB=1 -I"C:/Users//Documents/R/win-library/3.6/Rcpp/include" -I"C:/Users//Documents/R/win-library/3.6/RcppEigen/include" -I"C:/Users//Documents/R/win-library/3.6/BH/include" -I"C:/RLibrary/StanHeaders/include" -I"C:/Users//Documents/R/win-library/3.6/RcppParallel/include" -DRCPP_PARALLEL_USE_TBB=1 -O3 -march=corei7 -mtune=corei7 -c stan_fit.cpp -o stan_fit.o
c:/Rtools/mingw_64/bin/ar -rs …/inst/lib//x64/libStanServices.a stan_fit.o stan_fit_base.o
C:\Rtools\mingw_64\bin\ar.exe: creating …/inst/lib//x64/libStanServices.a
installing to C:/RLibrary/00LOCK-rstan/00new/rstan/libs/x64
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
converting help for package ‘rstan’
finding HTML links … done
As.mcmc.list html …
Rd warning: C:/Users//AppData/Local/Temp/RtmpCqkTTr/R.INSTALL312c4d97522/rstan/man/plotting-functions.Rd:19: file link ‘stan_ac’ in package ‘rstan’ does not exist and so has been treated as a topic
print.stanfit html …
Rd warning: C:/Users//AppData/Local/Temp/RtmpCqkTTr/R.INSTALL312c4d97522/rstan/man/stanfit-method-loo.Rd:11: file link ‘loo.array’ in package ‘loo’ does not exist and so has been treated as a topic
Rd warning: C:/Users//AppData/Local/Temp/RtmpCqkTTr/R.INSTALL312c4d97522/rstan/man/stanfit-method-loo.Rd:60: file link ‘loo.array’ in package ‘loo’ does not exist and so has been treated as a topic
stanfit-method-pairs html …
*** copying figures
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
*** arch - i386
*** arch - x64
** testing if installed package can be loaded from final location
*** arch - i386
*** arch - x64
** testing if installed package keeps a record of temporary installation path

  • DONE (rstan)
    Warning messages:
    1: In untar2(tarfile, files, list, exdir, restore_times) :
    failed to copy ‘stan-dev-rstan-fef82e9/StanHeaders/inst/include/mathlib/lib/sundials_4.1.0’ to ‘stan-dev-rstan-fef82e9/StanHeaders/inst/include/libsundials’
    2: In untar2(tarfile, files, list, exdir, restore_times) :
    failed to copy ‘stan-dev-rstan-fef82e9/StanHeaders/inst/include/upstream/src’ to ‘stan-dev-rstan-fef82e9/StanHeaders/inst/include/src’
    3: In untar2(tarfile, files, list, exdir, restore_times) :
    failed to copy ‘stan-dev-rstan-fef82e9/StanHeaders/inst/include/mathlib/stan’ to ‘stan-dev-rstan-fef82e9/StanHeaders/inst/include/stan’
    4: In untar2(tarfile, files, list, exdir, restore_times) :
    skipping pax global extended headers
    5: In untar2(tarfile, files, list, exdir, restore_times) :
    skipping pax global extended headers

library(rstan)
Loading required package: StanHeaders
Loading required package: ggplot2
rstan (Version 2.21.1, GitRev: 2e1f913d3ca3)
fit ← stan(file = ‘8schools.stan’, data = schools_dat)
Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! In file included from file4dd84eaf67ab.cpp:498:0:
C:/RLibrary/rstan/include/rstan_next/stan_fit.hpp:7:37: fatal error: stan/model/model_base.hpp: No such file or directory
#include <stan/model/model_base.hpp>
^
compilation terminated.
make: *** [C:/PROGRA~1/R/R-36~1.3/etc/x64/Makeconf:215: file4dd84eaf67ab.o] Error 1
In addition: Warning message:
In system(cmd, intern = !verbose) :
running command ‘C:/PROGRA~1/R/R-36~1.3/bin/x64/R CMD SHLIB file4dd84eaf67ab.cpp 2> file4dd84eaf67ab.cpp.err.txt’ had status 1
Error in sink(type = “output”) : invalid connection

You are probably going to need to

source("https://raw.githubusercontent.com/stan-dev/rstan/develop/StanHeaders/install-github.R")
install_StanHeaders(rstan_branch = "develop", math_branch = "StanHeaders_2.21", library_branch = "StanHeaders_2.21")

assuming you have already done

2 Likes

Thanks, that worked perfectly. Dev version is installed ok and runs a basic model.