When building Docker containers (or CI things for, like, GitHub) for #rstats, is there a way to know which apt-based packages you need to install beforehand? I always end up rebuilding, finding a new error, googling the name of the missing library, and repeating over and over until it builds and *surely* there's a better way??
@andrew https://eddelbuettel.github.io/r2u/#docker this should help and make everything faster? They have a docker container at rocker/r2u
CRAN as Ubuntu Binaries - r2u

Easy, fast, reliable -- pick all three!

@erikjan @andrew r2u is the way to go if you only want tp work with the last versions of every package (x10 faster and dependency intelligent), pak otherwise. Here compared http://github.com/jrosell/playground4rocker
GitHub - jrosell/playground4rocker: Github actions and docker deployment workflows for R projects.

Github actions and docker deployment workflows for R projects. - jrosell/playground4rocker

GitHub
@andrew checkout the pak package https://pak.r-lib.org/reference/pkg_sysreqs.html
You can get install_scripts for your platform. I combine it with renv and the dockerfiler package in my CI pipelines to build the docker containers.
Calculate system requirements of one of more packages โ€” pkg_sysreqs

Calculate system requirements of one of more packages

@friessn @andrew do you have any example Dockerfiles you could share?
@joelnitta @andrew
Sure, here are two screenshots of the r script and the resulting dockerfile for a quick minimal example shiny app that loads the RPostgres package and thus needs libpq-dev

@friessn @andrew Thanks!

Have you ever tried dockerfiler::dock_from_renv()? Looks like it could replace much of that code, if I understand correctly (but I can also see why you might want finer control over what ends up in the Dockerfile)

https://thinkr-open.github.io/dockerfiler/reference/dock_from_renv.html

Create a Dockerfile from an `renv.lock` file โ€” dock_from_renv

Create a Dockerfile from an `renv.lock` file

@joelnitta @andrew yes exactly, I do it for the finer control. I think I couldn't for example choose r2u as a base image, but I could be wrong. I know I had reasons, but I cannot remember what they were ;-)

@andrew
Maybe
apt-cache depends <pkg>?

Like:
> apt-cache depends r-base
>r-base
> Depends: r-base-core
> Depends: r-recommended
> Recommends: r-base-html
> Recommends: r-doc-html
> Suggests: elpa-ess
> |Suggests: r-doc-info
> Suggests: r-doc-pdf

For example (root required for `apt install`):

apt-cache depends r-base | grep 'Depends:' | awk '{print $2}' | xargs apt install

@andrew
Sorry I missread, you mean when installing r-packages.

Posit package manager might help. It tell you for each package and distro the install commands necessary for system dependencies.

https://packagemanager.posit.co/client/#/repos/cran/packages/overview?search=igraph

Posit Package Manager

@andrew installing pak package and then let pak install the required system packages for you. It works most of the times.
@andrew Posit public package manager lists all the system dependencies for your system of choice! e.g. for {sf}: https://packagemanager.posit.co/client/#/repos/cran/packages/overview?search=Sf
Posit Package Manager

@andrew I just replied over on the bluer sky site mentioning #r2u (and thanks to @erikjan and @jrosell who mentioned it here) with post a quick post (https://bsky.app/profile/eddelbuettel.com/post/3ks7ifs2tw32l) and a follow-up (https://bsky.app/profile/eddelbuettel.com/post/3ks7j6yaq522h) showing a minimal Dockerfile and its use. 43 seconds here. #rstats

#r2u: Fast. Easy. Reliable.

Dirk Eddelbuettel (@eddelbuettel.com)

If you base your container on r2u you can write `install.packages()` listing the #Rstats packages. `bspm` then _resolves all R packages by installing the apt package and their dependencies_ via the integration to the system manager. #r2u. Fast. Easy, Reliable. eddelbuettel.github.io/r2u/ https://eddelbuettel.github.io/r2u/

Bluesky Social

@andrew If you use one of the rig containers [1], it is set up for binary R packages (on amd64) and automatic system package installation (or any arch), so all you need is

FROM ghcr.io/r-lib/rig/ubuntu-22.04-release
RUN R -q -e 'pak::pkg_install("tidyverse")'

Or you can use any container you like, install pak [2], and set up binary packages [3] manually if you like

[1] https://github.com/r-lib/rig#id-container
[2] https://pak.r-lib.org/reference/install.html
[3] https://packagemanager.posit.co/

GitHub - r-lib/rig: The R Installation Manager

The R Installation Manager. Contribute to r-lib/rig development by creating an account on GitHub.

GitHub

@andrew Also, if you just want to look them up, this works on any system:

pak::pkg_sysreqs("tidyverse", sysreqs_platform="ubuntu-22.04")

@gaborcsardi ahhh this is perfect! Thanks!

@andrew @gaborcsardi along this line, we've run into this problem enough that we've set up a GH action to check all our R-centric docker images for the sysdeps.

https://github.com/RMI-PACTA/actions/blob/main/.github/workflows/docker-check-R-sysdeps.yml

actions/.github/workflows/docker-check-R-sysdeps.yml at main ยท RMI-PACTA/actions

Actions for GitHub workflows. Contribute to RMI-PACTA/actions development by creating an account on GitHub.

GitHub
@andrew yeah I know what you mean. Well, there is no way to actually automate this (there is a package that can query package manager @posit but you can't really depends on that) but some strides have been made to make it easyer. Package manager is actually the most important a time saver and it will tell you the os deps. The way I do it is two docker files. One for apt and one with my app or pipeline, built from the former with renv cache shared amongst containers. It's documented and cool.