Guix shell, together with direnv and Emacs integration, is a lovely tool for installing R packages.
Guix already carries a lot of CRAN-packages, but sometimes I need something not already packaged, at the moment the mfp package.
To help my memory, here is a R function that takes a R package name and returns a tibble with all the information needed to write a Guix package:
library(dplyr);With the output of metadata_for_guix_packages("mfp"), we can easily cobble together a working Guix package definition:
library(glue);
library(tibble);
metadata_for_guix_packages <- function(package_name)
# Ask R for package details
available.packages()[package_name, c("Depends",
"Imports",
"Suggests",
"License",
"Version",
"Repository")] |>
as_tibble_row() |>
# Get sha256 from guix download
(\(x)
add_column(x, system2(command = "guix",
args = c("download",
glue("{x$Repository}/{package_name}_{x$Version}.tar.gz")),
stdout = TRUE)[2]))() |>
# Clean up return value
select(-Repository) |>
rename("SHA256" = "...[]");
(define r-mfp
(package
(name "r-mfp")
(version "1.5.4.1")
(source
(origin
(method url-fetch)
(uri (cran-uri "mfp" version))
(sha256
(base32 "17sww972ymnddbi54575hdalbshfq81m849795pmi38j3mrhz25m"))))
(build-system r-build-system)
(propagated-inputs (list r-survival r-numderiv))
(native-inputs (list r-knitr r-markdown))
(home-page "https://cran.r-project.org/web/packages/mfp/index.html")
(synopsis "R package for regression modelling using fractional polynomial functions")
(description "Fractional polynomials are used to represent curvature in regression models. A key reference is Royston and Altman, 1994.")
(license gpl2)))