Skip to content

Commit 9777eda

Browse files
committed
Install R before syncing in configure-test-env
In rig's admin mode, rig proj sync installs a missing R by re-running the whole command elevated, so the project library under tests/.rvenv ends up owned by root (r-lib/rig#503, fixed in rig's development version but not in 0.11.1). Setting up the test environment on a machine without the locked R then leaves a library the later dev rmarkdown and knitr installs cannot write to, and they fall back to the locked versions. Install R with rig add first, which does nothing when that version is already installed, then run rig proj sync --no-install-r as the calling user. This is the sequence the CI workflow already uses. Both configure-test-env.sh and configure-test-env.ps1 get it, since rig elevates the same way on Windows. Verified the already-installed path on Windows with both scripts. The missing-R path was not exercised.
1 parent fa74261 commit 9777eda

2 files changed

Lines changed: 19 additions & 5 deletions

File tree

‎tests/configure-test-env.ps1‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,19 @@ try { $null = gcm rig -ea stop; $rig=$true } catch {
55
}
66

77
If ($rig) {
8-
Write-Host -ForegroundColor green " > Syncing R packages from rproj.lock"
9-
rig proj sync
8+
# In admin mode rig proj sync installs a missing R by re-running itself
9+
# elevated, which leaves the project library owned by the admin account.
10+
# Install R separately (rig add does nothing when it is already installed),
11+
# then sync as this user.
12+
$rLockVersion = (Select-String -Path rproj.lock -Pattern '^r_version = "(.+)"' | Select-Object -First 1).Matches[0].Groups[1].Value
13+
Write-Host -ForegroundColor green " > Installing R $rLockVersion if missing"
14+
rig add $rLockVersion
15+
If ($LASTEXITCODE -eq 0) {
16+
Write-Host -ForegroundColor green " > Syncing R packages from rproj.lock"
17+
rig proj sync --no-install-r
18+
}
1019
If ($LASTEXITCODE -ne 0) {
11-
Write-Host -ForegroundColor red "rig proj sync failed - R tests will run without the locked packages"
20+
Write-Host -ForegroundColor red "Installing R or rig proj sync failed - R tests will run without the locked packages"
1221
} Else {
1322
# Installs on top of the lock must target the project library and the
1423
# exact R the sync used; rig's default is the default R's user library.

‎tests/configure-test-env.sh‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,13 @@ if [ -z "$rig_exists" ]
77
then
88
echo "No rig found in PATH - the R test environment is a rig project (rproj.toml). Install rig 0.11.1 or later: https://github.com/r-lib/rig"
99
else
10+
# In admin mode rig proj sync installs a missing R by re-running itself under
11+
# sudo, which leaves the project library owned by root. Install R separately
12+
# (rig add does nothing when it is already installed), then sync as this user.
13+
r_lock_version=$(sed -n 's/^r_version = "\(.*\)"/\1/p' rproj.lock | head -n 1 | tr -d '\r')
14+
echo " > Installing R $r_lock_version if missing"
1015
echo " > Syncing R packages from rproj.lock"
11-
if rig proj sync
16+
if rig add "$r_lock_version" && rig proj sync --no-install-r
1217
then
1318
# Installs on top of the lock must target the project library and the
1419
# exact R the sync used; rig's default is the default R's user library.
@@ -20,7 +25,7 @@ else
2025
rig pkg install --r-version "$r_version" --library "$r_lib" --with-repos https://yihui.r-universe.dev knitr \
2126
|| echo "Dev knitr not installed - tests use the locked version"
2227
else
23-
echo "rig proj sync failed - R tests will run without the locked packages"
28+
echo "Installing R or rig proj sync failed - R tests will run without the locked packages"
2429
fi
2530
fi
2631

0 commit comments

Comments
 (0)