Cannot open the connection issue: modeling using ulam

I am using Window system-10, 64bit, R- 4.0.2, RTools 40, rstan 2.19.3

I am trying to run the following model using ulam function (from the book Statistical rethinking):
m11.4<-ulam(
alist(
pulled_left ~dbinom(1,p),
logit§ <-a[actor]+b[treatment],
a[actor] ~dnorm(0,1.5),
b[treatment] ~dnorm(0,0.5)
),data=dat_list,chains=4,log_lik=TRUE)

I got the following error:

Error in file(con, “r”) : cannot open the connection
In addition: Warning messages:
1: In system(cmd, intern = !verbose) :
running command ‘C:/PROGRA~1/R/R-40~1.2/bin/x64/R CMD SHLIB file3e48ad46776.cpp 2> file3e48ad46776.cpp.err.txt’ had status 1
2: In file(con, “r”) :
cannot open file ‘file3e48ad46776.cpp.err.txt’: No such file or directory
Error in sink(type = “output”) : invalid connection

I tried several attempts using “RStan getting started page” and several posts similar to this (like editing Makevars.win file). However, I failed to address this. Any help appreciated.

Welcome to the forums!

Is your StanHeaders version 2.21? If so, that’s due to an issue when using rstan 2.19.3 with StanHeaders 2.21.

To get this working with ulam, you’ll need the appropriate version of StanHeaders. First, remove your old installations of RStan and StanHeaders:

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

Then restart R and use the following commands to install the appropriate StanHeaders alongside rstan:

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

After that, try your ulam model again and let us know how you go

1 Like

Hi Andrjohns: Version of StanHeaders is 2.21.0.5 and this doesn’t work.

What does:

packageVersion("rstan")
packageVersion("StanHeaders")

return?

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

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

Can you run:

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

Remove success. Got this error while installing package:

ERROR: compilation failed for package ‘StanHeaders’

Are there any error messages during the installation?

No. But after removing what previous error says. I got this now:

*** arch - i386
C:/Rtools/mingw_32/bin/gcc -I"C:/PROGRA~1/R/R-40~1.2/include" -DNDEBUG -DNO_FPRINTF_OUTPUT -I"…/inst/include" -include stan_sundials_printf_override.hpp -O2 -Wall -std=gnu99 -mfpmath=sse -msse2 -mstackrealign -c cvodes/cvodes_nls_stg1.c -o cvodes/cvodes_nls_stg1.o
sh: C:/Rtools/mingw_32/bin/gcc: No such file or directory
make: *** [C:/PROGRA~1/R/R-40~1.2/etc/i386/Makeconf:222: cvodes/cvodes_nls_stg1.o] Error 127
ERROR: compilation failed for package ‘StanHeaders’

This is indicating an issue with your RTools configuration. Can you delete your Makevars.win file and try again?

If that doesn’t work, can you post the output from:

Sys.getenv("BINPREF")
Sys.getenv("PATH")

Hi: I switched to R3.6 and RTool 3.5: I got the following error:

and my Makevars.win file contents this:
CXX14=$(BINPREF)g++ -O2 -march=native -mtune=native
CXX14FLAGS=-O3 -march=native -mtune=native
CXX11FLAGS=-O3 -march=native -mtune=native

Error is :
Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! g++.exe: error: Paudel/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.3/etc/x64/Makeconf:215: file3087272690e.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 file3087272690e.cpp 2> file3087272690e.cpp.err.txt’ had status 1
Error in sink(type = “output”) : invalid connection

This means that you’re using RStan 2.19 with StanHeaders 2.21 again

Then what is your suggestion.

A bit further up I posted instructions on removing StanHeaders and installing the right version, did you try those?

Copied again below:

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

Hi I have

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

Now,

this is the error:

Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! file4508c771d7c.cpp:6:36: warning: ISO C99 requires whitespace after the macro name
#define STAN__SERVICES__COMMAND_HPP#include <boost/integer/integer_log2.hpp>
^
file4508c771d7c.cpp:33:40: error: expected template-name before ‘<’ token
: public stan::model::model_base_crtp<model450838f8cc1_80e2b6267e3dc4ff0c2916d0cf0879e8> {
^
file4508c771d7c.cpp:33:40: error: expected ‘{’ before ‘<’ token
file4508c771d7c.cpp:33:40: error: expected unqualified-id before ‘<’ token
file4508c771d7c.cpp:573:1: error: expected ‘}’ at end of input
}
^
make: *** [C:/PROGRA~1/R/R-36~1.3/etc/x64/Makeconf:215: file4508c771d7c.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 file4508c771d7c.cpp 2> file4508c771d7c.cpp.err.txt’ had status 1
Error in sink(type = “output”) : invalid connection

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

That should be 2.19.2, did you copy the command from the above post or re-type it?

Can you re-run the above commands, making sure that you’re installing StanHeaders_2.19.2.tar.gz?

While installing “Stanheaders” i got following:

No man pages found in package ‘StanHeaders’
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
*** arch - i386
Error: package or namespace load failed for ‘StanHeaders’ in library.dynam(lib, package, package.lib):
DLL ‘StanHeaders’ not found: maybe not installed for this architecture?
Error: loading failed
Execution halted
*** arch - x64
ERROR: loading failed for ‘i386’

Can you try removing StanHeaders, then close and restart your R/RStudio session and try installing again?

This is the error after having StanHeaders 2.19.2:

Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! file1b8440457f66.cpp:6:36: warning: ISO C99 requires whitespace after the macro name
#define STAN__SERVICES__COMMAND_HPP#include <boost/integer/integer_log2.hpp>
^
file1b8440457f66.cpp:33:40: error: expected template-name before ‘<’ token
: public stan::model::model_base_crtp<model1b844c4810f0_80e2b6267e3dc4ff0c2916d0cf0879e8> {
^
file1b8440457f66.cpp:33:40: error: expected ‘{’ before ‘<’ token
file1b8440457f66.cpp:33:40: error: expected unqualified-id before ‘<’ token
file1b8440457f66.cpp:573:1: error: expected ‘}’ at end of input
}
^
make: *** [C:/PROGRA~1/R/R-36~1.3/etc/x64/Makeconf:215: file1b8440457f66.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 file1b8440457f66.cpp 2> file1b8440457f66.cpp.err.txt’ had status 1
Error in sink(type = “output”) : invalid connection

Next steps is to re-start R/RStudio again, then remove RStan and reinstall from source:

install.packages("rstan", type="source")