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

As the title suggests, I am receiving the error message:

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

Most topics around this issue seem to revolve around reinstalling a certain library.

This may be the solution for me, but before I do that I think the following is interesting:

I have a .stan file, “a.stan”. I can run “a.stan” from R Studio. If I copy the .stan file to “a2.stan”, and try to run the R code again the code does not run. I have to cancel the code and I get the error shown above.

I am confused as to why I get the error for new .stan files, but not my old ones. I am worried that if I reinstall stan, my older .stan files will not work (I could just copy them to the newer version but I think this is an interesting situation).

I would understand if, for example, I installed a new version of R and my older .stan files were not working as I did not load a new library, or if I went back to an old version of R and had to reinstall stan to match the older version of R.

However, I am saying that my .stan files are working in R. I only have an issue if I create a new .stan file.

Can anyone advise with this?

I will add that I am not using R on my computer. I am using my universities cloud server. Perhaps an admin update could have caused this?

I am still confused since I imagined that a .stan file would work on any version of R. I thought I would just have to update the R version not change the .stan file itself.

The sink() error is a generic error when the rstan call fails. Can you post more of the output that is shown?

Update: The new .stan file does run. But I do have a new error.

I have 1000 datasets and I am running the same .stan file 1000 times and saving some summary statistics.

Around 100 simulations run at once. I have the results from the first 100 simulations, but I am receiving errors on the remaining simulations:

Loading required package: StanHeaders
Loading required package: ggplot2
rstan (Version 2.19.3, GitRev: 2e1f913d3ca3)
For execution on a local, multicore CPU with excess RAM we recommend calling
options(mc.cores = parallel::detectCores()).
To avoid recompilation of unchanged Stan programs, we recommend calling
rstan_options(auto_write = TRUE)
Error in readRDS(file.rds) :
ReadItem: unknown type 0, perhaps written by later version of R
Calls: stan → stan_model → is → readRDS
Execution halted
srun: error: sb089: task 0: Exited with exit code 1

I wonder why this error does not show for the first 100 simulations.

The issue has resolved itself. I wonder if this was an issue with the servers yesterday. I wanted to close this topic since it turned out to not be stan related, but I do not have the rights to do that.

The solution to this was to comment out (or delete)

rstan_options(auto_write = TRUE)