Stan model

Can you please help I am trying to run the script but the program aborts
The error message is
Error in compileCode(f, code, language = language, verbose = verbose) : Compilation ERROR, function(s)/method(s) not created! file4248353f3ad7.cpp:6:36: warning: ISO C99 requires whitespace after the macro name #define STAN__SERVICES__COMMAND_HPP#include <boost/integer/integer_log2.hpp> ^ file4248353f3ad7.cpp:33:40: error: expected template-name before ‘<’ token : public stan::model::model_base_crtp<model424843e9427a_974aa441eafec1bb4df62c61c118f4b9> { ^ file4248353f3ad7.cpp:33:40: error: expected ‘{’ before ‘<’ token file4248353f3ad7.cpp:33:40: error: expected unqualified-id before ‘<’ token file4248353f3ad7.cpp:515:1: error: expected ‘}’ at end of input } ^ make: *** [C:/PROGRA~1/R/R-36~1.0/etc/x64/Makeconf:215: file4248353f3ad7.o] Error 1

Can you run:

example(stan_model,run.dontrun = TRUE,verbose=TRUE)

And post the line that starts with error:?

1 Like

Thanks for your interest on helping me
When I try to run the code it appears
Building R package from source requires installation of additional build tools
Do you want to install additional tools now?
And the error
Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! file32c43fc36e32.cpp:6:36: warning: ISO C99 requires whitespace after the macro name
#define STAN__SERVICES__COMMAND_HPP#include <boost/integer/integer_log2.hpp>
^
file32c43fc36e32.cpp:33:40: error: expected template-name before ‘<’ token
: public stan::model::model_base_crtp<model32c429612e54_73fc79f8b1915e8208c736914c86d1a1> {
^
file32c43fc36e32.cpp:33:40: error: expected ‘{’ before ‘<’ token
file32c43fc36e32.cpp:33:40: error: expected unqualified-id before ‘<’ token
file32c43fc36e32.cpp:371:1: error: expected ‘}’ at end of input
}
^
make: *** [C:/PROGRA~1/R/R-36~1.0/etc/x64/Makeconf:215: file32c43fc36e32.o] Error 1
In addition: Warning message:
In find.package(package, lib.loc, verbose = verbose) :
package ‘base’ found more than once, using the first from
“C:/PROGRA~1/R/R-36~1.0/library/base”,
“C:/Program Files/R/R-3.6.0/library/base”
When I click on No and try to run example(stan_model,run.dontrun = TRUE,verbose=TRUE
The same message appears

Do you have RTools 3.5 installed and you’ve gone through the Installation guide on the wiki: https://github.com/stan-dev/rstan/wiki/RStan-Getting-Started?

1 Like

Hello
I have installed the latest version of Rtools
I tried to run again your script and I have got another error message
Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! g++.exe: error: Figueiredo/Documents/R/win-library/3.6/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp: No such file or directory
make: *** [C:/PROGRA~1/R/R-36~1.0/etc/x64/Makeconf:215: file4ac08b77d4d.o] Error 1
In addition: Warning message:
In find.package(package, lib.loc, verbose = verbose) :
package ‘base’ found more than once, using the first from
“C:/PROGRA~1/R/R-36~1.0/library/base”,
“C:/Program Files/R/R-3.6.0/library/base”

Great, that’s good progress! That means that version of the StanHeaders packages has gotten ahead of the version of the rstan package. To fix that error, you need to remove rstan and stanheaders:

remove.packages(c("rstan","StanHeaders"))

Then restart R and run:

install.packages("https://cran.r-project.org/src/contrib/Archive/StanHeaders/StanHeaders_2.19.2.tar.gz", type="source",repos=NULL)
install.packages("rstan")

Then test if the installation has worked:

library(rstan)
example(stan_model,run.dontrun = TRUE,verbose=TRUE)
1 Like

Unfortenatly the error persist
Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! file4268566a430e.cpp:6:36: warning: ISO C99 requires whitespace after the macro name
#define STAN__SERVICES__COMMAND_HPP#include <boost/integer/integer_log2.hpp>
^
file4268566a430e.cpp:33:40: error: expected template-name before ‘<’ token
: public stan::model::model_base_crtp<model426816d875c0_73fc79f8b1915e8208c736914c86d1a1> {
^
file4268566a430e.cpp:33:40: error: expected ‘{’ before ‘<’ token
file4268566a430e.cpp:33:40: error: expected unqualified-id before ‘<’ token
file4268566a430e.cpp:371:1: error: expected ‘}’ at end of input
}
^
make: *** [C:/PROGRA~1/R/R-36~1.0/etc/x64/Makeconf:215: file4268566a430e.o] Error 1
In addition: Warning message:
In find.package(package, lib.loc, verbose = verbose) :
package ‘base’ found more than once, using the first from
“C:/PROGRA~1/R/R-36~1.0/library/base”,
“C:/Program Files/R/R-3.6.0/library/base”

What’s the output of:

readLines("~/.R/Makevars.win")
1 Like

The output is
[1] “” “CXX14FLAGS=-O3 -march=native -mtune=native”
[3] “CXX11FLAGS=-O3 -march=corei7 -mtune=corei7” “”
[5] “CXX14FLAGS=-O3 -march=native -mtune=native” “CXX11FLAGS=-O3 -march=corei7 -mtune=corei7”
[7] “” “CXX14FLAGS=-O3 -march=native -mtune=native”
[9] “CXX11FLAGS=-O3 -march=corei7 -mtune=corei7”

Could you also re-run the example model:

example(stan_model,run.dontrun = TRUE,verbose=TRUE)

And copy the section after Compilation argument:? For example, on my machine this looks like:

Compilation argument:
 C:/PROGRA~1/R/R-40~1.0/bin/x64/R CMD SHLIB filebb82f5a2ce.cpp 2> filebb82f5a2ce.cpp.err.txt 
"C:/rtools40/mingw64/bin/"g++  -std=gnu++14 -I"C:/PROGRA~1/R/R-40~1.0/include" -DNDEBUG   -I"C:/Users/Andrew Johnson/Documents/R/win-library/4.0/Rcpp/include/"  -I"C:/Users/Andrew Johnson/Documents/R/win-library/4.0/RcppEigen/include/"  -I"C:/Users/Andrew Johnson/Documents/R/win-library/4.0/RcppEigen/include/unsupported"  -I"C:/Users/Andrew Johnson/Documents/R/win-library/4.0/BH/include" -I"C:/Users/Andrew Johnson/Documents/R/win-library/4.0/StanHeaders/include/src/"  -I"C:/Users/Andrew Johnson/Documents/R/win-library/4.0/StanHeaders/include/"  -I"C:/Users/Andrew Johnson/Documents/R/win-library/4.0/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     -O3 -Wno-unused-variable -Wno-unused-function -std=c++14 -march=native -mtune=native -Wno-deprecated-declarations -Wno-ignored-attributes -c filebb82f5a2ce.cpp -o filebb82f5a2ce.o

Just to see if there are any misconfigurations or missing compiler flags that RStan needs

1 Like

Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! filec2c2ebc5e81.cpp:6:36: warning: ISO C99 requires whitespace after the macro name
#define STAN__SERVICES__COMMAND_HPP#include <boost/integer/integer_log2.hpp>
^
filec2c2ebc5e81.cpp:33:40: error: expected template-name before ‘<’ token
: public stan::model::model_base_crtp<modelc2c40a157e9_73fc79f8b1915e8208c736914c86d1a1> {
^
filec2c2ebc5e81.cpp:33:40: error: expected ‘{’ before ‘<’ token
filec2c2ebc5e81.cpp:33:40: error: expected unqualified-id before ‘<’ token
filec2c2ebc5e81.cpp:371:1: error: expected ‘}’ at end of input
}
^
make: *** [C:/PROGRA~1/R/R-36~1.0/etc/x64/Makeconf:215: filec2c2ebc5e81.o] Error 1
In addition: Warning message:
In find.package(package, lib.loc, verbose = verbose) :
package ‘base’ found more than once, using the first from
“C:/PROGRA~1/R/R-36~1.0/library/base”,
“C:/Program Files/R/R-3.6.0/library/base”

I need the section that starts with Compilation argument:, like the example I posted above

1 Like

Sorry
Compilation argument:
C:/PROGRA~1/R/R-36~1.0/bin/x64/R CMD SHLIB filec2c2f36ad2.cpp 2> filec2c2f36ad2.cpp.err.txt
C:/Rtools/mingw_64/bin/g++ -std=gnu++11 -I"C:/PROGRA~1/R/R-36~1.0/include" -DNDEBUG -I"C:/Users/Ivone Figueiredo/Documents/R/win-library/3.6/Rcpp/include/" -I"C:/Users/Ivone Figueiredo/Documents/R/win-library/3.6/RcppEigen/include/" -I"C:/Users/Ivone Figueiredo/Documents/R/win-library/3.6/RcppEigen/include/unsupported" -I"C:/Users/Ivone Figueiredo/Documents/R/win-library/3.6/BH/include" -I"C:/Users/Ivone Figueiredo/Documents/R/win-library/3.6/StanHeaders/include/src/" -I"C:/Users/Ivone Figueiredo/Documents/R/win-library/3.6/StanHeaders/include/" -I"C:/Users/Ivone Figueiredo/Documents/R/win-library/3.6/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 -O3 -march=corei7 -mtune=corei7 -c filec2c2f36ad2.cpp -o filec2c2f36ad2.o
filec2c2f36ad2.cpp:6:36: warning: ISO C99 requires whitespace after the macro name
#define STAN__SERVICES__COMMAND_HPP#include <boost/integer/integer_log2.hpp>
^
filec2c2f36ad2.cpp:33:40: error: expected template-name before ‘<’ token
: public stan::model::model_base_crtp<modelc2c20ca56ec_73fc79f8b1915e8208c736914c86d1a1> {
^
filec2c2f36ad2.cpp:33:40: error: expected ‘{’ before ‘<’ token
filec2c2f36ad2.cpp:33:40: error: expected unqualified-id before ‘<’ token
filec2c2f36ad2.cpp:371:1: error: expected ‘}’ at end of input
}
^
make: *** [C:/PROGRA~1/R/R-36~1.0/etc/x64/Makeconf:215: filec2c2f36ad2.o] Error 1

ERROR(s) during compilation: source code errors or compiler configuration errors!

Hmm, I’m afraid I can’t see anything wrong with your setup sorry.

You might have better luck with @bgoodri here

thank you very for your help
How I can address @bgoodri h

What is packageVersion("rstan")?

Good morning
Rstan is a package allows one to conveniently fit Stan models from R (R Core Team 2014) and access the output, including posterior inferences and intermediate quantities such as evaluations of the log posterior density and its gradients RStan-Getting-Started.
THanks