Subject: bug#50841: rstan needs gfortran 9+

From: [email-masked]
Date: Mon, 27 Sep 2021 09:33:37 +0000

Hi!

With Guix' package for R, it's not possible to use rstan or the things that depend on it at runtime, whether installed via Guix' r-rstan or via R's own package manager install.packages("rstan"). They install fine, but functions such as stan() and brm() try to call make, and then things crash and burn. The exception is the rstanarm package because it ships precompiled Stan models and doesn't need make.

The issue is basically that rstan needs access to gfortran 9+ at runtime (for some minimum GLIBCXX version), and it seems the core R must be defined with it.

You find a related error if you try install.packages("isoband"), which could work as a test case:

/gnu/store/741057r2x06zwg6zcmqmdyv51spm6n9i-gfortran-7.5.0-lib/lib/libstdc++.so.6: version `GLIBCXX_3.4.26' not found (required by /home/kept/Dotfiles/R/x86_64-unknown-linux-gnu-library/4.1/00LOCK-isoband/00new/isoband/libs/isoband.so)

I've been using custom package definitions that make it work, but for some unrelated reasons I'm having difficulty upgrading my package manifests, so I figured it's high time to fix this thing upstream. Here are my definitions:

(define-public gfortran-9
  (package
   (inherit ((@@ (gnu packages gcc) custom-gcc)
             gcc-9 "gfortran" '("fortran")
             (@@ (gnu packages gcc) %generic-search-paths)))
   (version "9")))

(define-public gfortran-toolchain-9
  (package
   (inherit (make-gcc-toolchain gfortran-9))))

(define-public r-minimal-me1
  (package
    (inherit (@ (gnu packages statistics) r-minimal))
    (version "4.99.99-me1")
    (inputs `(("gfortran" ,gfortran-9)
              ,@(alist-delete "gfortran"
                              (package-inputs (@ (gnu packages statistics) r-minimal)))))))

(define-public r-me1
  (package
   (inherit (@ (gnu packages statistics) r))
   (version "4.99.99-me1")
   (inputs `(("r-minimal" ,r-minimal-me1)
             ,@(alist-delete "r-minimal"
                             (package-inputs (@ (gnu packages statistics) r)))))))

;; add gcc and make at runtime, also needed
(define-public r-rstan-me1
  (package
   (inherit (@ (gnu packages cran) r-rstan))
   (version "2.99.99-me1")
   (propagated-inputs `(("gcc-toolchain" ,gcc-toolchain)
                        ("make" ,gnu-make)
                        ,@(package-propagated-inputs (@ (gnu packages cran) r-rstan))))))

(define-public r-igraph-me1
  (package
   (inherit (@ (gnu packages cran) r-igraph))
   (version "2021-me1")
   (inputs `(("r-minimal" ,r-minimal-me1)
             ,@(alist-delete "r-minimal"
                             (package-inputs (@ (gnu packages cran) r-igraph)))))
   (native-inputs `(("gfortran" ,gfortran-9)
                    ,@(alist-delete "gfortran"
                                    (package-native-inputs (@ (gnu packages cran) r-igraph)))))))

;; ... and all other packages depending on r-rstan need to point to the new r-rstan-me1, better fix r-rstan upstream