Renv packages installation order


I am using renv to keep track of the packages used in my project, the problem is that one of the packages I need (InSituType) does not declare a dependency. I added the undeclared dependency to the renv.lock file with renv::record("lsa")but when the project CI runs renv::restore() it tries to install InSituType before lsa and fails.

Is there a way to specify the order in which the packages should be installed by renv? Or, what is the recommended way of solving problems like this one?

Thank you!

I think this issue may be relevant. You could try enabling the pak installation backend and seeing if that helps.

Alternatively, if the project is open to accepting contributions, you could try to get a fix in upstream.

1 Like

Hi @edavidaja, thank you very much for your answer. Unfortunately I could not find any useful information in the linked GitHub issue. I also enabled the option to use pak in renv but it seems like pak is not yet used by renv::restore().

I reported the issue to the developers of InSituType and they acknowledged it, but they did not give me any estimate for when they will fix it.

When dealing with undeclared dependencies in R packages managed by renv, the issue you described can indeed be problematic, especially in CI/CD pipelines where package installation order is critical. Unfortunately, renv does not natively support specifying the order of package installations directly.

1 Like

Are you able to alter how renv::restore() is invoked on CI? If so, then you could try performing two separate restores, e.g.

renv::restore(packages = "lsa")

Note that any packages installed from the first restore would be re-used on the second restore.

@kevinushey thank you very much for your suggestion! I modified my CI as follow:

    runs-on: ubuntu-latest
      contents: write
      - name: Check out repository
        uses: actions/checkout@v4

      - name: Set up Quarto
        uses: quarto-dev/quarto-actions/setup@v2

      - name: Install R
        uses: r-lib/actions/setup-r@v2
          r-version: '4.4.0'

      - name: Run Bash commands
        run: |
          if (!requireNamespace("renv", quietly=TRUE)) install.packages("renv")
          renv::restore(packages = "lsa")
        shell: Rscript {0}

      - name: Install R Dependencies
        uses: r-lib/actions/setup-renv@v2
          cache-version: 1

      - name: Render and Publish
        uses: quarto-dev/quarto-actions/publish@v2
          target: gh-pages
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

But unfortunately it does not work, renv does not install lsa:

Run if (!requireNamespace("renv", quietly=TRUE)) install.packages("renv")
  if (!requireNamespace("renv", quietly=TRUE)) install.packages("renv")
  renv::restore(packages = "lsa")
  shell: /usr/local/bin/Rscript {0}
    BUNDLE_EXT: linux-amd64.deb
    R_LIBS_USER: /home/runner/work/_temp/Library
    TZ: UTC
    NOT_CRAN: true
# Bootstrapping renv 1.0.7 ---------------------------------------------------
- Downloading renv ... OK
- Installing renv  ... OK
- One or more packages recorded in the lockfile are not installed.
- Use `renv::status()` for more details.
'getOption("repos")' replaces Bioconductor standard repositories, see
'help("repositories", package = "BiocManager")' for details.
Replacement repositories:
- The library is already synchronized with the lockfile.