Error when running stan() in r

Hello!
Very new to RStan; so new that I haven’t been able to get it to work. Below is some code from a tutorial I found on line produced by Rasmus Baath:
library(rstan)

The Stan model as a string

model_string<- "
data {
// Number of trials
 int nA;
 int nB;
 // Number of successes
 int sA;
 int sB;
}

parameters {
 real<lower=0, upper=1> rateA;
 real<lower=0, upper=1> rateB;
}

model {
 rateA ~ uniform(0,1);
 rateB ~ uniform(0,1);
 sA ~ binomial(nA,rateA);
 sB ~ binomial(nB,rateB);
}

generated quantities {
 real rate_diff;
 rate_diff= rateB-rateA;
}
"
data_list <- list(nA=16, nB=16, sA=6, sB=10)

Compiling and producing posterior samples from the model

stan_samples <-stan(model_code=model_string, data=data_list)
###################################################
When I run the above code, I get the following error messages:

Error in file(con, "r") : cannot open the connection
In addition: Warning messages:
1: In system(cmd, intern = !verbose) :
  running command CMD SHLIB file340c3f4110d1.cpp 2> file340c3f4110d1.cpp.err.txt' had status 1
2: In file(con, "r") :
  cannot open file 'file340c3f4110d1.cpp.err.txt': No such file or directory
Error in sink(type = "output") : invalid connection

I assum this means I need file340c3f4110d1.cpp.err.txt, but I can’t find it and I don’t know where I got it or if I can get it again if somehow I had it and now I don’t. At this point, I’m wondering if I can get this file somewhere, or if this can only be fixed by removing all r and rstudio and start from scratch. Any recommendations would be very much appreciate it.

Thank you.
P

Start with

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

What is the line that includes error: (with the colon).

I’m not quite sure I understand your question, but here goes.

This line:
stan_samples <-stan(model_code=model_string, data=data_list)

resulted in this error message:

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

I think I understand now. I fan your code (i.e., example(stan_model, package = “rstan”, run.dontrun = TRUE))
Here is the line that includes error:
Error in file(con, “r”) : cannot open the connection
In addition: Warning message:
In file(con, “r”) :
cannot open file ‘file4e4021452a4b.cpp.err.txt’: No such file or directory

So I guess i need file4e4021452a4b.cpp.err.txt but I can’t find it.

There should be about 1000 more lines of output. We need the one with error: in it.

Oh. My bad. Sorry about that
How about this:

fatal error: stan/math/prim/mat/fun/Eigen.hpp: No such file or directory
compilation terminated.

You need to do

install.packages("StanHeaders")

I just installed StanHeaders and ran the code you gave me again (i.e., example(stan_model, package = “rstan”, run.dontrun = TRUE))

I got the same error message as before:

fatal error: stan/math/prim/mat/fun/Eigen.hpp: No such file or directory
compilation terminated.

Is there more on or before that line?

cc1plus.exe: fatal error: stan/math/prim/mat/fun/Eigen.hpp: No such file or directory
compilation terminated.

What is

system.file("include", "stan", "math", "prim", "mat", "fun", "Eigen.hpp", 
            package = "StanHeaders")

?

“\\oya.ad/Users/Central/gettyp/R/R-4.0.0/library/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp”

image001.jpg

There are a lot of difficulties when you install packages in network-mounted home directories on Windows. It is better to install them where R is installed.

Ok. So, it sounds like I need to uninstall and reinstall and have install packages directly on the machine? Or can I simply move the R folder to the computer?

Thank you very much, by the way, for coaching me through this. I appreciate it.

image001.jpg

Best to reinstall

Ok. That’s what I figured. Thank again for you help.

image001.jpg