stan-dev / rstanarm

rstanarm R package for Bayesian applied regression modeling
https://mc-stan.org/rstanarm
GNU General Public License v3.0
385 stars 132 forks source link

Struggling to build from source with R 4.2.1 #568

Open sambrilleman opened 2 years ago

sambrilleman commented 2 years ago

Summary:

Struggling to build rstanarm from source. I'm trying to bring the latest changes from master into the feature/survival branch and then build the package on Windows using R 4.2.1 and Rtools42. See the bottom of this post for my full traceback. Error feels familiar, but then again... 🤔

I want to get this build working with R 4.2 to try and start unblocking all the issues people are describing in #500.

Reproducible Steps:

  1. Clone the survival_2_21_3 branch: https://github.com/stan-dev/rstanarm/tree/survival_2_21_3
  2. Run roxygen2::roxygenize() on R 4.2.1 with Rtools42

RStanARM Version:

survival_2_21_3 branch

R Version:

4.2.1

Operating System:

Windows 11

> roxygen2::roxygenize()
ℹ Loading rstanarm
Re-compiling rstanarm
─  installing *source* package 'rstanarm' ...
   ** using staged installation
   Loading required package: Rcpp
   Loading required package: bayesplot
   This is bayesplot version 1.9.0
   - Online documentation and vignettes at mc-stan.org/bayesplot
   - bayesplot theme set to bayesplot::theme_default()
      * Does _not_ affect other ggplot2 plots
      * See ?bayesplot_theme_set for details on theme setting
   Loading required package: ggplot2
   Loading required package: lme4
   Loading required package: Matrix
   Loading required package: loo
   This is loo version 2.5.1
   - Online documentation and vignettes at mc-stan.org/loo
   - As of v2.0.0 loo defaults to 1 core but we recommend using as many as possible. Use the 'cores' argument or set options(mc.cores = NUM_CORES) for an entire session. 
   - Windows 10 users: loo may be very slow if 'mc.cores' is set in your .Rprofile file (see https://github.com/stan-dev/loo/issues/94).
   Loading required package: nlme

   Attaching package: 'nlme'

   The following object is masked from 'package:lme4':

       lmList

   Loading required package: rstan
   Loading required package: StanHeaders
   rstan (Version 2.21.5, 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)
   Do not specify '-march=native' in 'LOCAL_CPPFLAGS' or a Makevars file
   Loading required package: rstantools
   This is rstantools version 2.2.0
   Loading required package: shinystan
   Loading required package: shiny

   This is shinystan version 2.6.0

   Loading required package: splines
   Loading required package: splines2
   Loading required package: survival
   Loading required package: RcppParallel

   Attaching package: 'RcppParallel'

   The following object is masked from 'package:Rcpp':

       LdFlags

   Warning: [posterior_survfit.R:299] @examples has mismatched braces or quotes
   Warning: [posterior_survfit.R:1131] @examples has mismatched braces or quotes
   Warning: [posterior_traj.R:183] @examples has mismatched braces or quotes
   Warning: [posterior_traj.R:555] @examples has mismatched braces or quotes
   Warning: [ps_check.R:71] @examples has mismatched braces or quotes
   Writing 'NAMESPACE'
   Writing 'NAMESPACE'
   Writing 'as.matrix.stanreg.Rd'
   Writing 'bayes_R2.stanreg.Rd'
   Writing 'QR-argument.Rd'
   Writing 'adapt_delta.Rd'
   Writing 'available-algorithms.Rd'
   Writing 'rstanarm-datasets.Rd'
   Writing 'example_jm.Rd'
   Writing 'example_model.Rd'
   Writing 'available-models.Rd'
   Writing 'rstanarm-deprecated.Rd'
   Writing 'rstanarm-package.Rd'
   Writing 'reexports.Rd'
   Writing 'launch_shinystan.stanreg.Rd'
   Writing 'log_lik.stanreg.Rd'
   Writing 'kfold.stanreg.Rd'
   Writing 'loo_predict.stanreg.Rd'
   Writing 'loo.stanreg.Rd'
   Writing 'logit.Rd'
   Writing 'get_y.Rd'
   Writing 'get_surv.Rd'
   Writing 'neg_binomial_2.Rd'
   Writing 'plot.stanreg.Rd'
   Writing 'pairs.stanreg.Rd'
   Writing 'posterior_interval.stanreg.Rd'
   Writing 'posterior_linpred.stanreg.Rd'
   Writing 'posterior_predict.stanreg.Rd'
   Writing 'posterior_survfit.Rd'
   Writing 'print.survfit.stansurv.Rd'
   Writing 'plot.survfit.stanjm.Rd'
   Writing 'posterior_traj.Rd'
   Writing 'plot.predict.stanjm.Rd'
   Writing 'posterior_vs_prior.Rd'
   Writing 'pp_check.stanreg.Rd'
   Writing 'pp_validate.Rd'
   Writing 'predict.stanreg.Rd'
   Writing 'predictive_error.stanreg.Rd'
   Writing 'predictive_interval.stanreg.Rd'
   Writing 'print.stanreg.Rd'
   Writing 'summary.stanreg.Rd'
   Writing 'prior_summary.stanreg.Rd'
   Writing 'priors.Rd'
   Writing 'ps_check.Rd'
   Writing 'stan_lm.Rd'
   Writing 'stan_betareg.Rd'
   Writing 'stan_biglm.Rd'
   Writing 'stan_clogit.Rd'
   Writing 'stan_gamm4.Rd'
   Writing 'stan_glm.Rd'
   Writing 'stan_glmer.Rd'
   Writing 'stan_jm.Rd'
   Writing 'stan_mvmer.Rd'
   Writing 'stan_nlmer.Rd'
   Writing 'stan_polr.Rd'
   Writing 'stan_surv.Rd'
   Writing 'tve.Rd'
   Writing 'stanmvreg-methods.Rd'
   Writing 'terms.stanmvreg.Rd'
   Writing 'family.stanmvreg.Rd'
   Writing 'model.frame.stanmvreg.Rd'
   Writing 'stanreg-methods.Rd'
   Writing 'se.Rd'
   Writing 'family.stanreg.Rd'
   Writing 'model.frame.stanreg.Rd'
   Writing 'model.matrix.stanreg.Rd'
   Writing 'formula.stanreg.Rd'
   Writing 'terms.stanreg.Rd'
   Writing 'stanreg-objects.Rd'
   Writing 'stanreg_list.Rd'
   cp: cannot overwrite non-directory 'tests/testthat/stan_files' with directory 'src/stan_files'
   cp: cannot overwrite non-directory 'tests/testthat/include' with directory 'inst/include'
   ** libs
   "C:/PROGRA~1/R/R-42~1.1/bin/x64/Rscript" -e "source(file.path('..', 'tools', 'make_cc.R')); make_cc(commandArgs(TRUE))" stan_files/bernoulli.stan
   Wrote C++ file "stan_files/bernoulli.cc"

   g++  -std=gnu++14 -I"C:/PROGRA~1/R/R-42~1.1/include" -DNDEBUG -I"../inst/include" -I"C:/Program Files/R/R-4.2.1/library/StanHeaders/include/src" -DBOOST_DISABLE_ASSERTS -DEIGEN_NO_DEBUG -I'C:/Program Files/R/R-4.2.1/library/StanHeaders/include' -I'C:/Program Files/R/R-4.2.1/library/rstan/include' -I'C:/Program Files/R/R-4.2.1/library/BH/include' -I'C:/Program Files/R/R-4.2.1/library/Rcpp/include' -I'C:/Program Files/R/R-4.2.1/library/RcppEigen/include' -I'C:/Program Files/R/R-4.2.1/library/RcppParallel/include'   -I"C:/rtools42/x86_64-w64-mingw32.static.posix/include"  `"C:/PROGRA~1/R/R-42~1.1/bin/x64/Rscript" -e "RcppParallel::CxxFlags()"` `"C:/PROGRA~1/R/R-42~1.1/bin/x64/Rscript" -e "StanHeaders:::CxxFlags()"` -flto=jobserver   -O2 -Wall  -mfpmath=sse -msse2 -mstackrealign  -UNDEBUG -Wall -pedantic -g -O0 -fdiagnostics-color=always -UNDEBUG -Wall -pedantic -g -O0 -fdiagnostics-color=always -c stan_files/bernoulli.cc -o stan_files/bernoulli.o
   g++.exe:error: Files/R/R-4.2.1/library/RcppParallel/include": No such file or directory
   make: *** [C:/PROGRA~1/R/R-42~1.1/etc/x64/Makeconf:258: stan_files/bernoulli.o] Error 1
   rm stan_files/bernoulli.cc
   ERROR: compilation failed for package 'rstanarm'
─  removing 'C:/Users/SBRILL~1/AppData/Local/Temp/RtmpCM60dL/devtools_install_212818dd7db2/rstanarm'
Error in `(function (command = NULL, args = character(), error_on_status = TRUE, …`:
! System command 'Rcmd.exe' failed
---
Exit status: 1
stdout & stderr: <printed>
---
Type .Last.error to see the more details.
timhowes commented 2 years ago

I think the error comes from these lines in the cleanup.win script: https://github.com/stan-dev/rstanarm/blob/43b0796a2259165458dd9f5e0cbaf35853f7c3fd/cleanup.win#L5-L6

It tries to copy two folders to the testthat directory, but there are existing symlinks in those locations.

Probably, these two lines should be removed from cleanup.win. Alternatively, you could try deleting the symlinks at tests/testthat/stan_files and tests/testthat/stan_files before building.

timhowes commented 2 years ago

Actually, when I try installing on Windows 11 (having freshly installed RStudio, R, and Rtools42), it is able to build rstanarm, despite warnings about the copy commands failing. (Note: I did have to modify src/Makevars.win by removing -flto=jobserver and adding -Wa,-mbig-obj to the PKG_CXXFLAGS line, to avoid errors later in compilation). https://stackoverflow.com/questions/31890021/mingw-too-many-sections-bug-while-compiling-huge-header-file-in-qt https://digitalkarabela.com/mingw-w64-how-to-fix-file-too-big-too-many-sections/

In your case, it seems like it's not finding the RcppParallel package because it is not parsing the -I'C:/Program Files/R/R-4.2.1/library/RcppParallel/include' flag correctly. In my case, RcppParallel is installed under my user library, which doesn't have any spaces in the path.

The RcppParallel::LdFlags() function uses the utility function RcppParallel:::asBuildPath() to convert the paths to an abbreviated form without spaces on Windows. Maybe StanHeaders:::CxxFlags() and StanHeaders:::LdFlags() should do something similar to avoid issues. https://rdrr.io/cran/RcppParallel/src/R/utils.R https://github.com/stan-dev/rstan/issues/873

andrjohns commented 2 years ago

I believe the RcppParallel path issue is fixed under the 2.26 preview of StanHeaders as well