Error in sink(type = “output”) : invalid connection

Hi all,

I am pretty new with Stan. However, in the past months I have been able to run, without too many problems, various models. Recently, I have added a new model:

modelFitRef_LM <- stan(
  file = "deltaRuleLinearModel.stan",  # Stan program; make sure this is in the same directory you have declared at the top of this script.
  data = allDataStan,  # named list of data
  chains = 4,             # number of Markov chains
  warmup = 2000,          # number of warmup iterations per chain
  iter = 4000,            # total number of iterations per chain
  cores = 4,              # number of cores (could use one per chain)
  refresh = 0             # no progress shown
)

which is a very similar model to others that have presented no issue at all in running. In addition, colleagues of mine did not have any problems in running this script so I believe it is something wrong with my machine.
This is the error message that I receive:

Warning in system(paste(CXX, ARGS), ignore.stdout = TRUE, ignore.stderr = TRUE) :
  'C:/rtools40/usr/mingw_/bin/g++' not found
make cmd is
  make -f "C:/PROGRA~1/R/R-40~1.2/etc/x64/Makeconf" -f "C:/PROGRA~1/R/R-40~1.2/share/make/winshlib.mk" CXX='$(CXX14) $(CXX14STD)' CXXFLAGS='$(CXX14FLAGS)' CXXPICFLAGS='$(CXX14PICFLAGS)' SHLIB_LDFLAGS='$(SHLIB_CXX14LDFLAGS)' SHLIB_LD='$(SHLIB_CXX14LD)' SHLIB="file16907b108d9.dll" WIN=64 TCLBIN=64 OBJECTS="file16907b108d9.o"

make would use
"C:/rtools40/mingw64/bin/"g++  -std=gnu++14 -I"C:/PROGRA~1/R/R-40~1.2/include" -DNDEBUG   -I"C:/Users/ic18563/OneDrive - University of Bristol/Documents/R/win-library/4.0/Rcpp/include/"  -I"C:/Users/ic18563/OneDrive - University of Bristol/Documents/R/win-library/4.0/RcppEigen/include/"  -I"C:/Users/ic18563/OneDrive - University of Bristol/Documents/R/win-library/4.0/RcppEigen/include/unsupported"  -I"C:/Users/ic18563/OneDrive - University of Bristol/Documents/R/win-library/4.0/BH/include" -I"C:/Users/ic18563/OneDrive - University of Bristol/Documents/R/win-library/4.0/StanHeaders/include/src/"  -I"C:/Users/ic18563/OneDrive - University of Bristol/Documents/R/win-library/4.0/StanHeaders/include/"  -I"C:/Users/ic18563/OneDrive - University of Bristol/Documents/R/win-library/4.0/RcppParallel/include/"  -I"C:/Users/ic18563/OneDrive - University of Bristol/Documents/R/win-library/4.0/rstan/include" -DEIGEN_NO_DEBUG  -DBOOST_DISABLE_ASSERTS  -DBOOST_PENDING_INTEGER_LOG2_HPP  -DSTAN_THREADS  -DBOOST_NO_AUTO_PTR  -include "C:/Users/ic18563/OneDrive - University of Bristol/Documents/R/win-library/4.0/StanHeaders/include/stan/math/prim/mat/fun/Eigen.hpp"  -std=c++1y         -O2 -Wall  -mfpmath=sse -msse2 -mstackrealign -c file16907b108d9.cpp -o file16907b108d9.o
if test "zfile16907b108d9.o" != "z"; then \
  if test -e "file16907b108d9-win.def"; then \
    echo "C:/rtools40/mingw64/bin/"g++  -shared -s -static-libgcc -o file16907b108d9.dll file16907b108d9-win.def file16907b108d9.o   "C:/Users/ic18563/OneDrive - University of Bristol/Documents/R/win-library/4.0/rstan/lib/x64/libStanServices.a" -L"C:/Users/ic18563/OneDrive - University of Bristol/Documents/R/win-library/4.0/StanHeaders/libs/x64" -lStanHeaders -L"C:/Users/ic18563/OneDrive - University of Bristol/Documents/R/win-library/4.0/RcppParallel/lib/x64" -ltbb  -L"C:/PROGRA~1/R/R-40~1.2/bin/x64" -lR ; \
    "C:/rtools40/mingw64/bin/"g++  -shared -s -static-libgcc -o file16907b108d9.dll file16907b108d9-win.def file16907b108d9.o   "C:/Users/ic18563/OneDrive - University of Bristol/Documents/R/win-library/4.0/rstan/lib/x64/libStanServices.a" -L"C:/Users/ic18563/OneDrive - University of Bristol/Documents/R/win-library/4.0/StanHeaders/libs/x64" -lStanHeaders -L"C:/Users/ic18563/OneDrive - University of Bristol/Documents/R/win-library/4.0/RcppParallel/lib/x64" -ltbb  -L"C:/PROGRA~1/R/R-40~1.2/bin/x64" -lR ; \
  else \
    echo EXPORTS > tmp.def; \
    "C:/rtools40/mingw64/bin/"nm file16907b108d9.o | sed -n 's/^.* [BCDRT] / /p' | sed -e '/[.]refptr[.]/d' -e '/[.]weak[.]/d' | sed 's/[^ ][^ ]*/"&"/g'  >> tmp.def; \
    echo "C:/rtools40/mingw64/bin/"g++  -shared -s -static-libgcc -o file16907b108d9.dll tmp.def file16907b108d9.o   "C:/Users/ic18563/OneDrive - University of Bristol/Documents/R/win-library/4.0/rstan/lib/x64/libStanServices.a" -L"C:/Users/ic18563/OneDrive - University of Bristol/Documents/R/win-library/4.0/StanHeaders/libs/x64" -lStanHeaders -L"C:/Users/ic18563/OneDrive - University of Bristol/Documents/R/win-library/4.0/RcppParallel/lib/x64" -ltbb  -L"C:/PROGRA~1/R/R-40~1.2/bin/x64" -lR ; \
    "C:/rtools40/mingw64/bin/"g++  -shared -s -static-libgcc -o file16907b108d9.dll tmp.def file16907b108d9.o   "C:/Users/ic18563/OneDrive - University of Bristol/Documents/R/win-library/4.0/rstan/lib/x64/libStanServices.a" -L"C:/Users/ic18563/OneDrive - University of Bristol/Documents/R/win-library/4.0/StanHeaders/libs/x64" -lStanHeaders -L"C:/Users/ic18563/OneDrive - University of Bristol/Documents/R/win-library/4.0/RcppParallel/lib/x64" -ltbb  -L"C:/PROGRA~1/R/R-40~1.2/bin/x64" -lR ; \
    rm -f tmp.def; \
  fi \
fi
Error in compileCode(f, code, language = language, verbose = verbose) : 
                   from file16907b108d9.cpp:14:C:/Users/ic18563/OneDrive - University of Bristol/Documents/R/win-library/4.0/StanHeaders/include/stan/math/rev/core/set_zero_all_adjoints.hpp: At global scope:C:/Users/ic18563/OneDrive - University of Bristol/Documents/R/win-library/4.0/StanHeaders/include/stan/math/rev/core/set_zero_all_adjoints.hpp:14:13: warning: 'void stan::math::set_zero_all_adjoints()' defined but not used [-Wunused-function] static void set_zero_all_adjoints() {             ^~~~~~~~~~~~~~~~~~~~~make: *** [C:/PROGRA~1/R/R-40~1.2/etc/x64/Makeconf:229: file16907b108d9.o] Error 1
Error in sink(type = "output") : invalid connection

I have tried all the suggestions recommended in the forum without any success in solving the issue.
I am using this R version:
RStudio Version 1.4.1717
and this Stan version:

 packageVersion("rstan")
[1] ‘2.21.2’

and I am working with Windows 10 Enterprise.

Please any suggestion is welcome! I have tried now to solve this problem for a while and without any success.
Many thanks in advance for your help!

Hi, sorry for not getting to you earlier.

It looks like your configuration/installation/toolchain broke at some point (possibly due to upgrading something else). Could you try either (re-)installing latest rstan (via Repository for distributing (some) stan-dev R packages | r-packages - unfortunately not on CRAN) which has some improved diagnostics, or try using cmdstanr (Getting started with CmdStanR • cmdstanr)?

Thanks Martin, using cmdstanr overran the problem!

1 Like