Skip to content

Commit 92f67a4

Browse files
authored
(R renv) Fix Renv package cache location in examples (#660)
* (R renv) Fix Renv package cache location in examples * (R env) Update getting Renv package cache location * (R env) Set renv package cache location using RENV_PATHS_ROOT environment variable
1 parent 6bbe742 commit 92f67a4

File tree

1 file changed

+26
-44
lines changed

1 file changed

+26
-44
lines changed

examples.md

+26-44
Original file line numberDiff line numberDiff line change
@@ -450,53 +450,35 @@ jobs:
450450

451451
## R - renv
452452

453-
For renv, the cache directory will vary by OS. Look at https://rstudio.github.io/renv/articles/renv.html#cache
454-
455-
Locations:
456-
457-
- Ubuntu: `~/.local/share/renv`
458-
- macOS: `~/Library/Application Support/renv`
459-
- Windows: `%LOCALAPPDATA%/renv`
460-
461-
### Simple example
462-
463-
```yaml
464-
- uses: actions/cache@v2
465-
with:
466-
path: ~/.local/share/renv
467-
key: ${{ runner.os }}-renv-${{ hashFiles('**/renv.lock') }}
468-
restore-keys: |
469-
${{ runner.os }}-renv-
470-
```
471-
472-
Replace `~/.local/share/renv` with the correct `path` if not using Ubuntu.
473-
474-
### Multiple OS's in a workflow
453+
For renv, the cache directory will vary by OS. The `RENV_PATHS_ROOT` environment variable is used to set the cache location. Have a look at https://rstudio.github.io/renv/reference/paths.html#details for more details.
475454

476455
```yaml
477-
- uses: actions/cache@v2
478-
if: startsWith(runner.os, 'Linux')
479-
with:
480-
path: ~/.local/share/renv
481-
key: ${{ runner.os }}-renv-${{ hashFiles('**/renv.lock') }}
482-
restore-keys: |
483-
${{ runner.os }}-renv-
484-
485-
- uses: actions/cache@v2
486-
if: startsWith(runner.os, 'macOS')
487-
with:
488-
path: ~/Library/Application Support/renv
489-
key: ${{ runner.os }}-renv-${{ hashFiles('**/renv.lock') }}
490-
restore-keys: |
491-
${{ runner.os }}-renv-
492-
493-
- uses: actions/cache@v2
494-
if: startsWith(runner.os, 'Windows')
456+
- name: Set RENV_PATHS_ROOT
457+
shell: bash
458+
run: |
459+
echo "RENV_PATHS_ROOT=${{ runner.temp }}/renv" >> $GITHUB_ENV
460+
- name: Install and activate renv
461+
run: |
462+
install.packages("renv")
463+
renv::activate()
464+
shell: Rscript {0}
465+
- name: Get R and OS version
466+
id: get-version
467+
run: |
468+
cat("##[set-output name=os-version;]", sessionInfo()$running, "\n", sep = "")
469+
cat("##[set-output name=r-version;]", R.Version()$version.string, sep = "")
470+
shell: Rscript {0}
471+
- name: Get renv cache path
472+
id: get-renv-cache-path
473+
run: |
474+
cat("##[set-output name=renv-cache-path;]", renv::paths$cache(), sep = "")
475+
shell: Rscript {0}
476+
- name: Restore Renv package cache
477+
uses: actions/cache@v2
495478
with:
496-
path: ~\AppData\Local\renv
497-
key: ${{ runner.os }}-renv-${{ hashFiles('**/renv.lock') }}
498-
restore-keys: |
499-
${{ runner.os }}-renv-
479+
path: ${{ env.RENV_PATHS_ROOT }}
480+
key: ${{ steps.get-version.outputs.os-version }}-${{ steps.get-version.outputs.r-version }}-${{ inputs.cache-version }}-${{ hashFiles('renv.lock') }}
481+
restore-keys: ${{ steps.get-version.outputs.os-version }}-${{ steps.get-version.outputs.r-version }}-${{inputs.cache-version }}-
500482
```
501483

502484
## Ruby - Bundler

0 commit comments

Comments
 (0)