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

Hello,

I have recently started using a new computer (Mac OS 12.2, R 4.1.2, brms 2.16.3). In my first session using R on the new computer, I receive first a pop-up message asking if I would “like to install build tools.” Regardless of what I select, the model does not compile and the following error message appears:

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

The full statement is:

make cmd is
make -f ‘/Library/Frameworks/R.framework/Resources/etc/Makeconf’ -f ‘/Library/Frameworks/R.framework/Resources/share/make/shlib.mk’ -f ‘/Users/JaredVasil/.R/Makevars’ CXX=’(CXX14) (CXX14STD)’ CXXFLAGS=’(CXX14FLAGS)' CXXPICFLAGS='(CXX14PICFLAGS)’ SHLIB_LDFLAGS=’(SHLIB_CXX14LDFLAGS)' SHLIB_LD='(SHLIB_CXX14LD)’ SHLIB=‘file3cd323fcb070.so’ OBJECTS=‘file3cd323fcb070.o’

make would use
if test “zfile3cd323fcb070.o” != “z”; then
echo clang++ -mmacosx-version-min=10.13 -std=gnu++14 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -Wl,-rpath,/Library/Frameworks/R.framework/Resources/lib /Library/Frameworks/R.framework/Resources/lib/libc++abi.1.dylib -L"/Library/Frameworks/R.framework/Resources/lib" -L/usr/local/lib -o file3cd323fcb070.so file3cd323fcb070.o ‘/Library/Frameworks/R.framework/Versions/4.1/Resources/library/rstan/lib//libStanServices.a’ -L’/Library/Frameworks/R.framework/Versions/4.1/Resources/library/StanHeaders/lib/’ -lStanHeaders -L’/Library/Frameworks/R.framework/Versions/4.1/Resources/library/RcppParallel/lib/’ -ltbb -F/Library/Frameworks/R.framework/… -framework R -Wl,-framework -Wl,CoreFoundation;
clang++ -mmacosx-version-min=10.13 -std=gnu++14 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -Wl,-rpath,/Library/Frameworks/R.framework/Resources/lib /Library/Frameworks/R.framework/Resources/lib/libc++abi.1.dylib -L"/Library/Frameworks/R.framework/Resources/lib" -L/usr/local/lib -o file3cd323fcb070.so file3cd323fcb070.o ‘/Library/Frameworks/R.framework/Versions/4.1/Resources/library/rstan/lib//libStanServices.a’ -L’/Library/Frameworks/R.framework/Versions/4.1/Resources/library/StanHeaders/lib/’ -lStanHeaders -L’/Library/Frameworks/R.framework/Versions/4.1/Resources/library/RcppParallel/lib/’ -ltbb -F/Library/Frameworks/R.framework/… -framework R -Wl,-framework -Wl,CoreFoundation;
fi
Error in compileCode(f, code, language = language, verbose = verbose) :
file3cd323fcb070.cpp:356:24: warning: unused typedef ‘local_scalar_t__’ [-Wunused-local-typedef] typedef double local_scalar_t__; ^28 warnings generated.clang: error: no such file or directory: '/Library/Frameworks/R.framework/Resources/lib/libc++abi.1.dylib’make: *** [file3cd323fcb070.so] Error 1
In addition: Warning message:
Rows containing NAs were excluded from the model.
Error in sink(type = “output”) : invalid connection

I have seen other threads about this topic (e.g., Error in sink(type = "output") : invalid connection ; c++ - Stan model will not compile in R or Rstudio - Stack Overflow). However, following the solutions I’ve come across has not helped. Any help with this issue is greatly appreciated, and I am happy to offer more information that may be of use. Thanks.

Update for anyone who comes across this later. I fixed the issue by uninstalling and reinstalling rstan, brms, and dependencies. Next, I uninstalled the R development toolchain, following:

Uninstalling the R development toolchain on macOS | The Coatless Professor

Next, I followed:

R Compiler Tools for Rcpp on macOS | The Coatless Professor

to reinstall the Xcode CLI. Then, I reinstalled the appropriate gfortran for Monterey, at:

Release gfortran 12-experimental for ARM, macOS 12 (Monterey) · fxcoudert/gfortran-for-macOS · GitHub

I then restarted R, and now things seem to be working appropriately (model compiles and sampling proceeds in parallel without error). Will update if further issues arise.