Skip to content

Cache R installation on Windows #21

Closed

Description

@wch

On Windows, it would be useful to cache the R installation. I've been informed that the r-lib/actions/setup-r action doesn't just install R (and Rtools); it also sets up environment variables and PATH.

Activity

  1. changed the title [-]Cache R installation[/-] [+]Cache R installation on Windows[/+] on Dec 6, 2019
  2. jimhester commented on Dec 12, 2019

    @jimhester
    Member

    Another possible way to handle this might be making a Windows container with R + Rtools preinstalled, though that would require someone to maintain them, and who knows if it would actually be any faster to start up.

  3. wch commented on Dec 12, 2019

    @wch
    MemberAuthor

    This is only tangentially related, but for package caching on Windows (or anything that uses actions/cache), I found that you have to fix the path so that actions/cache doesn't try to use C:/Rtools/bin/tar.exe when it saves the cache. (I've filed this at actions/cache#125)

    Adding this to the end of a script will fix the problem, by pointing actions/cache to the tar.exe that it would normally use:

          - name: Fix path for Windows caching
            if: runner.os == 'Windows'
            run: echo "::add-path::C:/Program Files/Git/usr/bin"

    https://github.com/wch/gha/blob/4c9a1a0b92c17c1af0d5c8a95418b979add88447/.github/workflows/hello.yml#L90-L96

    UPDATE:
    Github has made some changes for security reasons, so now you have to do the following:

          - name: Fix path for Windows caching
            if: runner.os == 'Windows'
            run: echo "C:/Program Files/Git/usr/bin" >> $GITHUB_PATH

    Info here: https://github.blog/changelog/2020-10-01-github-actions-deprecating-set-env-and-add-path-commands/

  4. jimhester commented on Dec 12, 2019

    @jimhester
    Member

    That is a good way to fix it, #13 was the issue for that problem. It seems like partially a bug in the tar implementation shipped with RTools, it doesn't find the gzip executable also in RTools even though it is on the windows PATH.

  5. added
    feature
    on Apr 3, 2020
  6. jennybc commented on Dec 22, 2020

    @jennybc
    Member

    In my hands, it seems to be very important to specify the shell on Windows, which defaults to powershell. So here's the snippet I ended up using:

          - name: Fix path for Windows caching
            if: runner.os == 'Windows'
            shell: bash
            run: echo "C:/Program Files/Git/usr/bin" >> $GITHUB_PATH
  7. benthecoder commented on Feb 27, 2021

    @benthecoder
  8. jennybc commented on Feb 28, 2021

    @jennybc
  9. jennybc commented on Feb 28, 2021

    @jennybc
    Member

    Just re-confirmed that for "windows-latest + R 3.6" you really do need shell: bash if you want caching. I find this is not necessary for later versions of R (more specifically, the associated Rtools).

  10. florisvdh commented on Mar 20, 2021

    @florisvdh

    I find this is not necessary for later versions of R (more specifically, the associated Rtools).

    Same here, windows-latest + r-release (R 4.0.4) successfully used caching after dropping line 52 in:

    - name: Restore R package cache
    if: runner.os != 'Windows'
    uses: actions/cache@v2
    with:
    path: ${{ env.R_LIBS_USER }}
    key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }}
    restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-

    I tested it in a slightly modified version of the check-standard workflow, but I don't think those differences are relevant here.

    FWIW, this job took 9m 54s when the cache was not yet available (but created for the first time), and 3m 52s next time.

  11. github-actions commented on Nov 6, 2022

    @github-actions

    This issue has been automatically locked. If you believe you have found a related problem, please file a new issue and include a link to this issue

  12. locked as resolved and limited conversation to collaborators on Nov 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions