stan-dev / rstan

RStan, the R interface to Stan
https://mc-stan.org
1.02k stars 264 forks source link

rstan R 4.3.1 and rtools 4.3 #1078

Closed ploutal7 closed 1 year ago

ploutal7 commented 1 year ago

Summary:

Package rstan won't install properly (Windows 10); in particular, the fix that used to work stopped working with R 4.3.1.

Description:

I get an error when following the directions on the rstan installation page: https://github.com/stan-dev/rstan/wiki/RStan-Getting-Started.

Reproducible Steps:

First off, here's my system info: sysname release version machine "Windows" "10 x64" "build 19045" "x86-64" Next, my installed versions of R and rtools: R version 4.3.1 (2023-06-16 ucrt), and RTools 4.3 (rtools43-5550-5548)

Here's the R code and the error I get--this is code that USED to work with R 4.3.0 and RTools 4.3. My hunch is (based on the error I get when trying to install) that the directory at https://mc-stan.org/r-packages/ has not been set up for R 4.3.1 Windows packages yet, or maybe it's been altered recently:

install.packages(c("BH", "StanHeaders", "Rcpp", "RcppEigen", "RcppParallel", "inline", "loo", "pkgbuild", "rstan"), repos = c("https://mc-stan.org/r-packages/", getOption("repos")), dependencies=T, type="both") Installing packages into ‘C:/Users/louta/R Libraries’ (as ‘lib’ is unspecified) Warning: unable to access index for repository https://mc-stan.org/r-packages/bin/windows/contrib/4.3: cannot open URL 'https://mc-stan.org/r-packages/bin/windows/contrib/4.3/PACKAGES'

There is a binary version available but the source version is later: binary source needs_compilation rstan 2.21.8 2.26.22 TRUE

At this point, a pop-up dialogue appears, and I can either compile code from source or choose not to. Doesn't make any difference which I choose--either way, I get the same error when loading and running rstan example 1 (see Current Output below).

Current Output:

fit <- stan(file = 'schools.stan', data = schools_dat) hash mismatch so recompiling; make sure Stan code ends with a blank line make cmd is make -f "C:/PROGRA~1/R/R-4.3.1/etc/x64/Makeconf" -f "C:/PROGRA~1/R/R-4.3.1/share/make/winshlib.mk" CXX='$(CXX14) $(CXX14STD)' CXXFLAGS='$(CXX14FLAGS)' CXXPICFLAGS='$(CXX14PICFLAGS)' SHLIB_LDFLAGS='$(SHLIB_CXX14LDFLAGS)' SHLIB_LD='$(SHLIB_CXX14LD)' SHLIB="file4b683c4f33ac.dll" WIN=64 TCLBIN= OBJECTS="file4b683c4f33ac.o"

make would use if test "zfile4b683c4f33ac.o" != "z"; then \ if test -e "file4b683c4f33ac-win.def"; then \ echo g++ -shared -s -static-libgcc -o file4b683c4f33ac.dll file4b683c4f33ac-win.def file4b683c4f33ac.o -L"C:/rtools43/x86_64-w64-mingw32.static.posix/lib/x64" -L"C:/rtools43/x86_64-w64-mingw32.static.posix/lib" -L"C:/PROGRA~1/R/R-4.3.1/bin/x64" -lR ; \ g++ -shared -s -static-libgcc -o file4b683c4f33ac.dll file4b683c4f33ac-win.def file4b683c4f33ac.o -L"C:/rtools43/x86_64-w64-mingw32.static.posix/lib/x64" -L"C:/rtools43/x86_64-w64-mingw32.static.posix/lib" -L"C:/PROGRA~1/R/R-4.3.1/bin/x64" -lR ; \ else \ echo EXPORTS > tmp.def; \ nm file4b683c4f33ac.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 file4b683c4f33ac.dll tmp.def file4b683c4f33ac.o -L"C:/rtools43/x86_64-w64-mingw32.static.posix/lib/x64" -L"C:/rtools43/x86_64-w64-mingw32.static.posix/lib" -L"C:/PROGRA~1/R/R-4.3.1/bin/x64" -lR ; \ g++ -shared -s -static-libgcc -o file4b683c4f33ac.dll tmp.def file4b683c4f33ac.o -L"C:/rtools43/x86_64-w64-mingw32.static.posix/lib/x64" -L"C:/rtools43/x86_64-w64-mingw32.static.posix/lib" -L"C:/PROGRA~1/R/R-4.3.1/bin/x64" -lR ; \ rm -f tmp.def; \ fi \ fi Error in compileCode(f, code, language = language, verbose = verbose) : C:\rtools43\x86_64-w64-mingw32.static.posix\bin/ld.exe: file4b683c4f33ac.o:file4b683c4f33ac.cpp:(.text$_ZN3tbb8internal26task_scheduler_observer_v3D0Ev[_ZN3tbb8internal26task_scheduler_observer_v3D0Ev]+0x1c): undefined reference to tbb::internal::task_scheduler_observer_v3::observe(bool)'C:\rtools43\x86_64-w64-mingw32.static.posix\bin/ld.exe: file4b683c4f33ac.o:file4b683c4f33ac.cpp:(.text$_ZN3tbb10interface623task_scheduler_observerD1Ev[_ZN3tbb10interface623task_scheduler_observerD1Ev]+0x1c): undefined reference totbb::internal::task_scheduler_observer_v3::observe(bool)'C:\rtools43\x86_64-w64-mingw32.static.posix\bin/ld.exe: file4b683c4f33ac.o:file4b683c4f33ac.cpp:(.text$_ZN3tbb10interface623task_scheduler_observerD1Ev[_ZN3tbb10interface623task_scheduler_observerD1Ev]+0x37): undefined reference to `tbb::internal::task_scheduler_observer_v3::observe(bool)'C:\rtools43\x86_64-w64-mingw32.static.posix\bin/ld.exe: file4b683c4f33ac.o:file4b683c4f33ac.cpp:(.text$_ZN3tbb10interface Error in sink(type = "output") : invalid connection

Expected Output:

If applicable, the output you expected from RStan.

RStan Version:

The version of RStan you are running (e.g., from packageVersion("rstan"))

R Version:

R version 4.3.1 (2023-06-16 ucrt), and RTools 4.3 (rtools43-5550-5548)

Operating System:

"Windows" "10 x64" "build 19045"

psychelzh commented 1 year ago

Seemingly, we still need to resort to #1006.

ploutal7 commented 1 year ago

Do you mean

  1. Avoid upgrading to >= R 4.2? Or
  2. Install rstan from https://mc-stan.org/r-packages/ (after removing all the rstan dependencies that may have been installed from other repositories)?

I've already tried (2)--it's outlined in my post. It used to work, but it doesn't with R 4.3.1 and rtools 4.3. The error I got was:

Warning: unable to access index for repository https://mc-stan.org/r-packages/bin/windows/contrib/4.3: cannot open URL ' https://mc-stan.org/r-packages/bin/windows/contrib/4.3/PACKAGES'

If you try to go to https://mc-stan.org/r-packages/bin/windows/contrib/4.3/PACKAGES, you get a 404 error. I mentioned in the post that I thought the problem might be this directory has recently been changed, e.g., the name or directory structure was changed, and now R can't find it.

Paul

On Mon, Jul 3, 2023 at 12:38 PM Liang Zhang @.***> wrote:

Seemingly, we still need to resort to #1006 https://github.com/stan-dev/rstan/issues/1006.

— Reply to this email directly, view it on GitHub https://github.com/stan-dev/rstan/issues/1078#issuecomment-1618860423, or unsubscribe https://github.com/notifications/unsubscribe-auth/AY7BAO7MM3A24IDGZ63MOLLXOLYO5ANCNFSM6AAAAAAZSOP5RU . You are receiving this because you authored the thread.Message ID: @.***>

psychelzh commented 1 year ago

I ignored the warning and install it anyway. Then the installation also completed, and the example works without any error.

ploutal7 commented 1 year ago

I did that, too, and got the error you see in my post when running the 8 Schools example. Can you tell me

  1. What version of R are you using?
  2. What version of rtools are you using?
  3. What's your OS (Windows 10?), and what's the version number?

Thanks, Paul

On Mon, Jul 3, 2023 at 9:49 PM Liang Zhang @.***> wrote:

I ignored the warning and install it anyway. Then the installation also completed, and the example works without any error.

— Reply to this email directly, view it on GitHub https://github.com/stan-dev/rstan/issues/1078#issuecomment-1619344811, or unsubscribe https://github.com/notifications/unsubscribe-auth/AY7BAOYDITYWZ6DFGWY6WLDXONZBZANCNFSM6AAAAAAZSOP5RU . You are receiving this because you authored the thread.Message ID: @.***>

psychelzh commented 1 year ago

I managed to show the reprex (what you want to see is in session info) without error:

library(rstan)
#> 载入需要的程辑包:StanHeaders
#> 
#> rstan version 2.26.22 (Stan version 2.26.1)
#> 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)
#> For within-chain threading using `reduce_sum()` or `map_rect()` Stan functions,
#> change `threads_per_chain` option:
#> rstan_options(threads_per_chain = 1)
#> Do not specify '-march=native' in 'LOCAL_CPPFLAGS' or a Makevars file
options(mc.cores = parallel::detectCores())
rstan_options(auto_write = TRUE)
writeLines(
"
// saved as schools.stan
data {
  int<lower=0> J;         // number of schools
  real y[J];              // estimated treatment effects
  real<lower=0> sigma[J]; // standard error of effect estimates
}
parameters {
  real mu;                // population treatment effect
  real<lower=0> tau;      // standard deviation in treatment effects
  vector[J] eta;          // unscaled deviation from mu by school
}
transformed parameters {
  vector[J] theta = mu + tau * eta;        // school treatment effects
}
model {
  target += normal_lpdf(eta | 0, 1);       // prior log-density
  target += normal_lpdf(y | theta, sigma); // log-likelihood
}
",
"schools.stan"
)
schools_dat <- list(J = 8, 
                    y = c(28,  8, -3,  7, -1,  1, 18, 12),
                    sigma = c(15, 10, 16, 11,  9, 11, 10, 18))
fit <- stan(file = 'schools.stan', data = schools_dat)
#> Warning: There were 3 divergent transitions after warmup. See
#> https://mc-stan.org/misc/warnings.html#divergent-transitions-after-warmup
#> to find out why this is a problem and how to eliminate them.
#> Warning: Examine the pairs() plot to diagnose sampling problems

Created on 2023-07-04 with reprex v2.0.2

Session info ``` r sessioninfo::session_info() #> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R version 4.3.1 (2023-06-16 ucrt) #> os Windows 11 x64 (build 22621) #> system x86_64, mingw32 #> ui RTerm #> language (EN) #> collate Chinese (Simplified)_China.utf8 #> ctype Chinese (Simplified)_China.utf8 #> tz Asia/Shanghai #> date 2023-07-04 #> pandoc 3.1.2 @ C:/PROGRA~1/Pandoc/ (via rmarkdown) #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> ! package * version date (UTC) lib source #> callr 3.7.3 2022-11-02 [1] CRAN (R 4.3.0) #> cli 3.6.1 2023-03-23 [1] CRAN (R 4.3.0) #> codetools 0.2-19 2023-02-01 [2] CRAN (R 4.3.1) #> colorspace 2.1-0 2023-01-23 [1] CRAN (R 4.3.0) #> crayon 1.5.2 2022-09-29 [1] CRAN (R 4.3.0) #> curl 5.0.1 2023-06-07 [1] CRAN (R 4.3.0) #> digest 0.6.32 2023-06-26 [1] CRAN (R 4.3.1) #> dplyr 1.1.2 2023-04-20 [1] CRAN (R 4.3.0) #> evaluate 0.21 2023-05-05 [1] CRAN (R 4.3.0) #> fansi 1.0.4 2023-01-22 [1] CRAN (R 4.3.0) #> fastmap 1.1.1 2023-02-24 [1] CRAN (R 4.3.0) #> fs 1.6.2 2023-04-25 [1] CRAN (R 4.3.0) #> generics 0.1.3 2022-07-05 [1] CRAN (R 4.3.0) #> ggplot2 3.4.2 2023-04-03 [1] CRAN (R 4.3.0) #> glue 1.6.2 2022-02-24 [1] CRAN (R 4.3.0) #> gridExtra 2.3 2017-09-09 [1] CRAN (R 4.3.0) #> gtable 0.3.3 2023-03-21 [1] CRAN (R 4.3.0) #> htmltools 0.5.5 2023-03-23 [1] CRAN (R 4.3.0) #> inline 0.3.19 2021-05-31 [1] CRAN (R 4.3.1) #> jsonlite 1.8.7 2023-06-29 [1] CRAN (R 4.3.1) #> knitr 1.43 2023-05-25 [1] CRAN (R 4.3.0) #> lifecycle 1.0.3 2022-10-07 [1] CRAN (R 4.3.0) #> loo 2.6.0 2023-03-31 [1] CRAN (R 4.3.1) #> magrittr 2.0.3 2022-03-30 [1] CRAN (R 4.3.0) #> matrixStats 1.0.0 2023-06-02 [1] CRAN (R 4.3.1) #> munsell 0.5.0 2018-06-12 [1] CRAN (R 4.3.0) #> pillar 1.9.0 2023-03-22 [1] CRAN (R 4.3.0) #> pkgbuild 1.4.2 2023-06-26 [1] CRAN (R 4.3.1) #> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.3.0) #> prettyunits 1.1.1 2020-01-24 [1] CRAN (R 4.3.0) #> processx 3.8.2 2023-06-30 [1] CRAN (R 4.3.1) #> ps 1.7.5 2023-04-18 [1] CRAN (R 4.3.0) #> purrr 1.0.1 2023-01-10 [1] CRAN (R 4.3.0) #> R.cache 0.16.0 2022-07-21 [1] CRAN (R 4.3.0) #> R.methodsS3 1.8.2 2022-06-13 [1] CRAN (R 4.3.0) #> R.oo 1.25.0 2022-06-12 [1] CRAN (R 4.3.0) #> R.utils 2.12.2 2022-11-11 [1] CRAN (R 4.3.0) #> R6 2.5.1 2021-08-19 [1] CRAN (R 4.3.0) #> Rcpp 1.0.10 2023-01-22 [1] CRAN (R 4.3.0) #> D RcppParallel 5.1.7 2023-02-27 [1] CRAN (R 4.3.0) #> reprex 2.0.2 2022-08-17 [1] CRAN (R 4.3.0) #> rlang 1.1.1 2023-04-28 [1] CRAN (R 4.3.0) #> rmarkdown 2.23 2023-07-01 [1] CRAN (R 4.3.1) #> rstan * 2.26.22 2023-07-03 [1] local #> rstudioapi 0.14 2022-08-22 [1] CRAN (R 4.3.0) #> scales 1.2.1 2022-08-20 [1] CRAN (R 4.3.0) #> sessioninfo 1.2.2 2021-12-06 [1] CRAN (R 4.3.0) #> StanHeaders * 2.26.27 2023-06-14 [1] CRAN (R 4.3.1) #> styler 1.10.1 2023-06-05 [1] CRAN (R 4.3.0) #> tibble 3.2.1 2023-03-20 [1] CRAN (R 4.3.0) #> tidyselect 1.2.0 2022-10-10 [1] CRAN (R 4.3.0) #> utf8 1.2.3 2023-01-31 [1] CRAN (R 4.3.0) #> V8 4.3.2 2023-06-30 [1] CRAN (R 4.3.1) #> vctrs 0.6.3 2023-06-14 [1] CRAN (R 4.3.0) #> withr 2.5.0 2022-03-03 [1] CRAN (R 4.3.0) #> xfun 0.39 2023-04-20 [1] CRAN (R 4.3.0) #> yaml 2.3.7 2023-01-23 [1] CRAN (R 4.3.0) #> #> [1] C:/Users/lenovo/AppData/Local/R/win-library/4.3 #> [2] C:/Program Files/R/R-4.3.1/library #> #> D ── DLL MD5 mismatch, broken installation. #> #> ────────────────────────────────────────────────────────────────────────────── ```
psychelzh commented 1 year ago

FYI, wiki tells us to do so in Configuring-C---Toolchain-for-Windows. I think you should install Rtools 4.3 and just install rstan from source codes fetched from mc-stan.org.

remove.packages(c("StanHeaders", "rstan"))
install.packages(c("StanHeaders", "rstan"), repos = "https://mc-stan.org/r-packages/")
ploutal7 commented 1 year ago

As I mentioned in my original post, I DID ignore those warnings--it still wouldn't run on my computer. You're using Windows 11, but I'm using Windows 10; I think that's the difference here. Paul

On Tue, Jul 4, 2023 at 8:02 AM Liang Zhang @.***> wrote:

FYI, wiki tells us to do so in Configuring-C---Toolchain-for-Windows https://github.com/stan-dev/rstan/wiki/Configuring-C---Toolchain-for-Windows. So, afaik, it is okay to ignore those warnings.

— Reply to this email directly, view it on GitHub https://github.com/stan-dev/rstan/issues/1078#issuecomment-1620119726, or unsubscribe https://github.com/notifications/unsubscribe-auth/AY7BAO573NWQ42CFUBY6PATXOQA6ZANCNFSM6AAAAAAZSOP5RU . You are receiving this because you authored the thread.Message ID: @.***>

psychelzh commented 1 year ago

You should choose to install from source not the binary one. That makes a difference.

ploutal7 commented 1 year ago

YOU HAVEN"T READ MY ORIGINAL POST. I TRIED INSTALLING FROM SOURCE--IT DIDN"T WORK.

On Tue, Jul 4, 2023 at 7:30 PM Liang Zhang @.***> wrote:

You should choose to install from source not the binary one. That makes a difference.

— Reply to this email directly, view it on GitHub https://github.com/stan-dev/rstan/issues/1078#issuecomment-1620828404, or unsubscribe https://github.com/notifications/unsubscribe-auth/AY7BAO3AD4NYVI56E5F26W3XOSRSVANCNFSM6AAAAAAZSOP5RU . You are receiving this because you authored the thread.Message ID: @.***>

ploutal7 commented 1 year ago

Closing issue. Am receiving comments from users who clearly have NOT read through the original post.

psychelzh commented 1 year ago

It is a little ill-formatted. Anyway, I am now clear you have tried both source and binary versions. Some clues are: