Running rstan with latest R (3.6.0) fails with Error in compileCode

You need

I was able to run the command you gave to install rstan. However, I get a warning when I run the command you gave to install StanHeaders:

install.packages(c( "https://win-builder.r-project.org/cFk94LNBnN4N/StanHeaders_2.19.2.zip", repos = NULL, type = "win.binary"))

Warning in install.packages :
  packages ‘https://win-builder.r-project.org/cFk94LNBnN4N/StanHeaders_2.19.2.zip’, ‘win.binary’ are not available (for R version 3.6.1)

I was able to install win binaries for StanHeaders, though, using the following command:

install.packages("StanHeaders", type = "win.binary", dependencies = TRUE)

But, I’m still getting the error even after install StanHeaders:

Error in compileCode(f, code, language = language, verbose = verbose) : 
  Compilation ERROR, function(s)/method(s) not created! g++.exe: error: Files/R/R-3.6.1/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp: No such file or directory
g++.exe: error: Files/R/R-3.6.1/library/StanHeaders/include: No such file or directory
g++.exe: error: Files/R/R-3.6.1/library/RcppEigen/include: No such file or directory
make: *** [C:/PROGRA~1/R/R-36~1.1/etc/x64/Makeconf:215: file3bd47a296885.o] Error 1

I meant to write

install.packages(
"https://win-builder.r-project.org/cFk94LNBnN4N/StanHeaders_2.19.2.zip",
repos = NULL, type = "win.binary")

That worked, thanks!

Hello, I am using R64-bit 3.6.1 on windows 10 also (Version 2.19.3)

Compiling the C++ model
Error in compileCode(f, code, language = language, verbose = verbose) : 
  Compilation ERROR, function(s)/method(s) not created! In file included from <command-line>:0:0:
C:/Program Files/R/R-3.6.1/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp:4:23: fatal error: Eigen/Dense: No such file or directory
 #include <Eigen/Dense>
                       ^
compilation terminated.
make: *** [C:/PROGRA~1/R/R-36~1.1/etc/x64/Makeconf:215: file3b3463527e6a.o] Error 1
In addition: Warning message:
In system(cmd, intern = !verbose) :

so I tried

install.packages(
+     "https://win-builder.r-project.org/cFk94LNBnN4N/StanHeaders_2.19.2.zip",
+     repos = NULL, type = "win.binary")

Installing package into ‘\\svfas5.epfl.ch/Users_SV/betka/My Documents/R/win-library/3.6’
(as ‘lib’ is unspecified)
trying URL 'https://win-builder.r-project.org/cFk94LNBnN4N/StanHeaders_2.19.2.zip'
Warning in install.packages :
  cannot open URL 'https://win-builder.r-project.org/cFk94LNBnN4N/StanHeaders_2.19.2.zip': HTTP status was '404 Not Found'
Error in download.file(p, destfile, method, mode = "wb", ...) : 
  cannot open URL 'https://win-builder.r-project.org/cFk94LNBnN4N/StanHeaders_2.19.2.zip'

Could you help me ?
thanks

Do you have RcppEigen installed?

I just installed it

and

Error in compileCode(f, code, language = language, verbose = verbose) : 
  Compilation ERROR, function(s)/method(s) not created! file3ab49076cf0.cpp:6:36: warning: ISO C99 requires whitespace after the macro name
 #define STAN__SERVICES__COMMAND_HPP#include <boost/integer/integer_log2.hpp>
                                    ^
In file included from C:/Program Files/R/R-3.6.1/library/rstan/include/rstan/rstaninc.hpp:3:0,
                 from file3ab49076cf0.cpp:7:
C:/Program Files/R/R-3.6.1/library/rstan/include/rstan/stan_fit.hpp:13:59: fatal error: boost/date_time/posix_time/posix_time_types.hpp: No such file or directory
 #include <boost/date_time/posix_time/posix_time_types.hpp>
                                                           ^
compilation terminated.
make: *** [C:/PROGRA~1/R/R-36~1.1/etc/x64/Makeconf:215: file3ab49076cf0.o] Error 1
In addition: Warning message:
In system(cmd, intern = !verbose) :

You need the BH package as well.

ok but I still get the same error.

Does

system.file("include", "boost", "date_time", "posix_time", 
            "posix_time_types.hpp", package = "BH", mustWork = TRUE)

work?

system.file(“include”, “boost”, “date_time”, “posix_time”,

  •         "posix_time_types.hpp", package = "BH", mustWork = TRUE)
    

[1] “\\svfas5.epfl.ch/Users_SV/betka/My Documents/R/win-library/3.6/BH/include/boost/date_time/posix_time/posix_time_types.hpp”

Ah. These networked home directories usually mess things up. Do you have the option to install Rcpp, RcppEIgen, BH, StanHeaders, etc. to a physical disk on that machine?

Yes, I did actually library (xxx, lib=“C:/Program Files/R/R-3.6.1/library”), but not sure how to change the path written in the error.

I would try uninstalling those packages from your home directory and then it will probably fine them under C:/.

1 Like

It worked. thanks a lot and sorry for the inconvenience.

Hello!
I am kind of facing a similar problem. while running a stan model, I am getting the following error.

Error in compileCode(f, code, language = language, verbose = verbose) : **
** Compilation ERROR, function(s)/method(s) not created! C:/rtools40/mingw64/bin/…/lib/gcc/x86_64-w64-mingw32/8.3.0/…/…/…/…/x86_64-w64-mingw32/bin/ld.exe: file7a8441c6984.o:file7a8441c6984.cpp:(.text$_ZN4stan4math17cvodes_integratorILi2EE9integrateIN35model7a83b725807_model13d_namespace14SEIR_functor__EddEESt6vectorIS6_INS_11return_typeIT0_JT1_EE4typeESaISB_EESaISD_EERKT_RKS6_IS8_SaIS8_EEdRKS6_IdSaIdEERKS6_IS9_SaIS9_EESQ_RKS6_IiSaIiEEPSoddl[_ZN4stan4math17cvodes_integratorILi2EE9integrateIN35model7a83b725807_model13d_namespace14SEIR_functor__EddEESt6vectorIS6_INS_11return_typeIT0_JT1_EE4typeESaISB_EESaISD_EERKT_RKS6_IS8_SaIS8_EEdRKS6_IdSaIdEERKS6_IS9_SaIS9_EESQ_RKS6_IiSaIiEEPSoddl]+0x26d): undefined reference to `N_VMake_Serial’

C:/rtools40/mingw64/bin/…/lib/gcc/x86_64-w64-mingw32/8.3.0/…/…/…/…/x86_64-w64-mingw32/bin/ld.exe: file7a8441c6984.o:file7a8441c6984.cpp:(.text$_ZN4stan4math17cvodes_integratorILi2EE9integrateIN35model7a83b725807_model13d_namespace14SEIR_functor
Error in sink(type = “output”) : invalid connection

I am using “R version 4.0.0” and “rtools40” for my 64 bit windows 10 laptop.
Please help!
Thanks.
Moumita.

Does

example(stan_model, package = "rstan", run.dontrun = TRUE)

work?

Yes, it is working!
Then what should I modify in my existing one?

Not sure, what is your existing Stan code?

Thank you so much for your reply.
I used my_model = stan_model(“model_new.stan”) code to run the Stan code and my Stan code is

model_new.stan (13.3 KB)