Unable to install rstan (R version 4.2; Windows)

Hello All,

I am unable to install Rstan and StanHeaders for this URL Repository for distributing (some) stan-dev R packages | r-packages

RTools42 is installed on my system and is located at: C:\rtools42
It is present in the system variables (RTOOLS42_HOME)

When I try installing these libraries:

install.packages("StanHeaders", repos = c("https://mc-stan.org/r-packages/", getOption("repos")))
install.packages("rstan", repos = c("https://mc-stan.org/r-packages/", getOption("repos")))

It still uses the cran mirror. Here is the console output:

Warning in install.packages :
  unable to access index for repository https://mc-stan.org/r-packages/src/contrib:
  cannot open URL 'https://mc-stan.org/r-packages/src/contrib/PACKAGES'
Warning in install.packages :
  unable to access index for repository https://mc-stan.org/r-packages/bin/windows/contrib/4.2:
  cannot open URL 'https://mc-stan.org/r-packages/bin/windows/contrib/4.2/PACKAGES'
trying URL 'http://cran.rstudio.com/bin/windows/contrib/4.2/rstan_2.21.8.zip'
Content type 'application/zip' length 3340207 bytes (3.2 MB)
downloaded 3.2 MB

When I run the example model I get this error:

make cmd is
  make -f "C:/Users/DEEPAN~1.ARO/DOCUME~1/R-42~1.0/etc/x64/Makeconf" -f "C:/Users/DEEPAN~1.ARO/DOCUME~1/R-42~1.0/share/make/winshlib.mk" CXX='$(CXX14) $(CXX14STD)' CXXFLAGS='$(CXX14FLAGS)' CXXPICFLAGS='$(CXX14PICFLAGS)' SHLIB_LDFLAGS='$(SHLIB_CXX14LDFLAGS)' SHLIB_LD='$(SHLIB_CXX14LD)' SHLIB="file3720454b764a.dll" WIN=64 TCLBIN= OBJECTS="file3720454b764a.o"

make would use
if test "zfile3720454b764a.o" != "z"; then \
  if test -e "file3720454b764a-win.def"; then \
    echo g++  -shared -s -static-libgcc -o file3720454b764a.dll file3720454b764a-win.def file3720454b764a.o  -L"C:/rtools42/x86_64-w64-mingw32.static.posix/lib/x64" -L"C:/rtools42/x86_64-w64-mingw32.static.posix/lib"  -L"C:/Users/DEEPAN~1.ARO/DOCUME~1/R-42~1.0/bin/x64" -lR ; \
    g++  -shared -s -static-libgcc -o file3720454b764a.dll file3720454b764a-win.def file3720454b764a.o  -L"C:/rtools42/x86_64-w64-mingw32.static.posix/lib/x64" -L"C:/rtools42/x86_64-w64-mingw32.static.posix/lib"  -L"C:/Users/DEEPAN~1.ARO/DOCUME~1/R-42~1.0/bin/x64" -lR ; \
  else \
    echo EXPORTS > tmp.def; \
    nm file3720454b764a.o | sed -n 's/^.* [BCDRT] / /p' | sed -e '/[.]refptr[.]/d' -e '/[.]weak[.]/d' | sed 's/[^ ][^ ]*/"&"/g'  >> tmp.def; \
    echo g++  -shared -s -static-libgcc -o file3720454b764a.dll tmp.def file3720454b764a.o  -L"C:/rtools42/x86_64-w64-mingw32.static.posix/lib/x64" -L"C:/rtools42/x86_64-w64-mingw32.static.posix/lib"  -L"C:/Users/DEEPAN~1.ARO/DOCUME~1/R-42~1.0/bin/x64" -lR ; \
    g++  -shared -s -static-libgcc -o file3720454b764a.dll tmp.def file3720454b764a.o  -L"C:/rtools42/x86_64-w64-mingw32.static.posix/lib/x64" -L"C:/rtools42/x86_64-w64-mingw32.static.posix/lib"  -L"C:/Users/DEEPAN~1.ARO/DOCUME~1/R-42~1.0/bin/x64" -lR ; \
    rm -f tmp.def; \
  fi \
fi
Error in compileCode(f, code, language = language, verbose = verbose) : 
  C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: file3720454b764a.o:file3720454b764a.cpp:(.text$_ZN3tbb8internal26task_scheduler_observer_v3D0Ev[_ZN3tbb8internal26task_scheduler_observer_v3D0Ev]+0x1d): undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)'C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: file3720454b764a.o:file3720454b764a.cpp:(.text$_ZN3tbb10interface623task_scheduler_observerD1Ev[_ZN3tbb10interface623task_scheduler_observerD1Ev]+0x1d): undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)'C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: file3720454b764a.o:file3720454b764a.cpp:(.text$_ZN3tbb10interface623task_scheduler_observerD1Ev[_ZN3tbb10interface623task_scheduler_observerD1Ev]+0x3a): undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)'C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: file3720454b764a.o:file3720454b764a.cpp:(.text$_ZN3tbb10interface
Error in sink(type = "output") : invalid connection

Any help would be appreciated!!
Thanks!

Can you try installing the preview from source:

install.packages("StanHeaders", repos = c("https://mc-stan.org/r-packages/", getOption("repos")), type="source")
install.packages("rstan", repos = c("https://mc-stan.org/r-packages/", getOption("repos")), type="source")

I tried installing the preview from the source and it appeared that it installed perfectly. Each of them took like 2-3 minutes to install. However, when I run the example I still get the same issue:

Error in compileCode(f, code, language = language, verbose = verbose) : 
  C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: file44585b732c6e.o:file44585b732c6e.cpp:(.text$_ZN3tbb8internal26task_scheduler_observer_v3D0Ev[_ZN3tbb8internal26task_scheduler_observer_v3D0Ev]+0x1d): undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)'C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: file44585b732c6e.o:file44585b732c6e.cpp:(.text$_ZN3tbb10interface623task_scheduler_observerD1Ev[_ZN3tbb10interface623task_scheduler_observerD1Ev]+0x1d): undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)'C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: file44585b732c6e.o:file44585b732c6e.cpp:(.text$_ZN3tbb10interface623task_scheduler_observerD1Ev[_ZN3tbb10interface623task_scheduler_observerD1Ev]+0x3a): undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)'C:\rtools42\x86_64-w64-mingw32.static.posix\bin/ld.exe: file44585b732c6e.o:file44585b732c6e.cpp:(.text$_ZN3tbb10interface
Error in sink(type = "output") : invalid connection

Hello!
My rstan version is 2.21.8 and StanHeaders version is 2.26.27. Could this be a potential reason why I’m getting the sink error? On my work computer, we have zscaler which is potentially blocking this URL - https://mc-stan.org/r-packages/bin/windows/contrib/4.2/rstan_2.26.22.zip

Therefore, it ends up downloading the libraries from the cran. The most recent version for stanheaders on cran is 2.26.27 and rstan is 2.21.8.