Error in sink(type = "output") : invalid connection

Hello,

I’m new to running stan code and seem to be having issues having my model run in R.

Versions:

R 4.6.0

RTools 4.5

rstan 2.32.7

StanHeaders 2.39.1

Rcpp 1.1.2

I’ve tried running a simple model to test whether R can compile the code correctly and I keep on encountering the error:

Error in sink(type = "output") : invalid connection

I’m using this model to check whether it works:

stancode <- 'data {real y_mean;} parameters {real y;} model {y ~ normal(y_mean,1);}'
mod <- stan_model(model_code = stancode, verbose = TRUE)

If anyone could point me towards what I can do to debug the problem, that would be really helpful as I’m needing to start running some larger models soon.

Thanks in advance,
Kieran

Welcome to the Stan forum. RStan redirects output while it compiles your model, and if the C++ compilation fails then the cleanup step will error like this and hide the real problem unfortunately. Since you set verbose = TRUE, I think the actual compiler error should be printed somewhere further up in the output. Could you post the first error lines from there if you can find them? That should tell us what’s actually going wrong here.

Also, can you run pkgbuild::has_build_tools(debug = TRUE) and post the output? That should help us confirm that R is actually able to find and use Rtools45.