r-lib / pak

A fresh approach to package installation
https://pak.r-lib.org
639 stars 56 forks source link

`pak` in Github action fails to install `jpeg` package #656

Closed dmurdoch closed 2 days ago

dmurdoch commented 2 days ago

I use r-lib/actions/setup-r-dependencies@v2 in my R CMD check action for rgl. Lately it has been failing on MacOS because pak can't install the jpeg package. For example,

https://github.com/dmurdoch/rgl/actions/runs/9700088248/job/26770652832

Am I doing something wrong here, or is the a problem with pak?

(I have also posted this question on the Posit page here: https://forum.posit.co/t/github-action-fails-to-install-jpeg-package/188603 )

gaborcsardi commented 2 days ago

setup-r-dependencies does not install system packages on macOS, if you are building packages from source, then you need to do that yourself.

dmurdoch commented 2 days ago

Thanks for the suggestion, but that's not working for me. I added brew install libjpeg in the appropriate place, and that didn't work, possibly because of a conflict with libjpeg-turbo. I tried brew install libjpeg-turbo, and had the same jpeg package install failure. The latest version had this section:

  - name: Install dependencies on MacOS
    if: runner.os == 'macOS'
    run: |
      brew install xquartz
      brew install fribidi
      brew install libjpeg-turbo

and the previous one was the same except without the "turbo".

gaborcsardi commented 2 days ago

I am not sure if the jpeg package builds with libjpeg from brew, it seems to me that it does not, at least not out of the box.

dmurdoch commented 2 days ago

I think you're right. I don't know enough about the ins and outs of MacOS installs to continue with this, so I've dropped the MacOS R-devel target: for R-release it can get a binary install from CRAN.

dmurdoch commented 2 days ago

I came back to this, and took part of https://github.com/s-u/R-actions/blob/master/pkg-check/action.yml that installs libs on MacOS. Here's the step that worked for me:

  - name: Install jpeg library on MacOS
    if: runner.os == 'macOS'
    run: |
      ARCH=`uname -m`
      if [ ! -e /opt/R/$ARCH ]; then sudo mkdir -p /opt/R/$ARCH; sudo chown -R $USER /opt/R; fi
      sudo Rscript -e 'dep="jpeg"; source("https://mac.R-project.org/bin/install.R"); install.libs(dep)'
      if ! echo $PATH | grep /opt/R/$ARCH/bin >/dev/null; then echo /opt/R/$ARCH/bin > newPATH; cat $GITHUB_PATH >> newPATH; cat newPATH > $GITHUB_PATH; fi
    shell: bash

For other problematic libs on MacOS, change dep to a character vector of the names. See https://mac.r-project.org/bin/ for some docs on the approach.