Repository navigation
warn when a project asks for a different r version, and offer to switch via rig - #18935
Conversation
…ch via rig When a project's renv lockfile (or its .Rproj RVersion field) records a different major.minor of R than the one running, show a warning bar that offers to switch to that R. A version that is not installed is installed first via rig (user mode by default) in a background job; rig itself is downloaded when no copy is found. Switching reuses the existing quit path with an RVersionSpec; the desktop applies the requested R before launching the next session and remembers it. When the renv library is empty and the versions agree, offer renv::restore(). Versioned macOS framework installs are queried through bin/exec/R with their own R_HOME, since the shared launcher script always runs the framework's Current version. Addresses #12622
RStudio E2E - all platformsAll tests passed!
View / download the full reportView report online -- opens in the browser, no download needed. Available for 14 days. Download playwright-report.zip -- extract and open
All platforms - commit |
- escape versions and errors shown in the warning bar, and ignore lockfile or project versions that aren't version numbers - pick the rsession build (arm64/x86_64, UCRT, i386) for each launch, so a switch to another R gets the matching one - don't persist a switch on macOS/Linux; on Windows, clear the use-default flags so the stored choice holds at the next launch - validate the requested R before quitting, and drop a pending switch when the quit is abandoned - query framework installs through their own ldpaths, and query every R with the library path RStudio was launched with - refuse rig_install_r_version outside desktop mode; verify the rig download against pinned SHA-256 digests - honor stop requests before the first poll; avoid the job reference cycle - handle an install completion that arrives before the RPC response - only enforce the minimum R version; judge support by the R that would run - find the lockfile as renv does (profiles, directory overrides) and parse it once - find installed R without rig, derive homes without running R, prefer native builds on Apple silicon - run the check after startup, only for new sessions, and skip the rig lookup on server - remove unused rig helpers and the rig_list_r_versions RPC; register the warning bar action handler once; tidy the e2e test
…ess review round 2 - detect macOS framework versions whose launcher still runs the framework's default R; ask before making them orthogonal (as rig system make-orthogonal does), with an administrator prompt when the files aren't writable, and refuse to switch to one that isn't - store a Windows switch only once a session has started with it - keep the warning bar (and its offer) up until the quit goes ahead, and offer a retry when a switch fails - always install R in rig's user mode; pass over rig older than the pinned release; detect Apple silicon under Rosetta - check the requested R off the Electron main process, and always answer the client's bridge callbacks - tolerate malformed lockfile R entries, truncated Mach-O tables and errors while looking for an installed R - e2e: switch back and close the project afterward, check the session's own verdict after the switch, and cover declining the update - keep the warning bar action by the dismiss button with a hand cursor; order the new client event IDs after the existing ones
…mework update The update test edits a system-wide R installation, so it runs only with PW_ALLOW_R_FRAMEWORK_UPDATE=1.
A session resumed from a suspend for restart now runs the check again, as renv's own check does; one resumed from an ordinary suspend still doesn't. RInitInfo records which kind of suspend a resumed session came from.
A page reloaded against a running session (e.g. a browser refresh) starts without the warning the previous page showed, so the check runs again for it, at most once at a time. The warning also reports an R installation in progress, so the reloaded page switches once it finishes.
…n-switch # Conflicts: # src/node/desktop/src/main/gwt-callback.ts # src/node/desktop/src/main/session-launcher.ts # src/node/desktop/test/unit/main/gwt-callback.test.ts
gtritchie
left a comment
There was a problem hiding this comment.
Ten findings, posted inline.
The NEWS.md one needs fixing before merge: the merge from main brought back 27 release-note entries that main had already moved to the 2026.10.0 release. Of the others, the lockfile lookup ignoring RENV_PATHS_RENV can make the check read the wrong lockfile. The rest are lower severity: messaging, edge cases, efficiency and test coverage.
|
|
||
| ### New | ||
| - ([#12622](https://github.com/rstudio/rstudio/issues/12622)): RStudio Desktop now warns when a project asks for a different version of R than the one running (as recorded in its renv lockfile, or in the project file), and offers to switch to it. A version that is not installed is installed first, via [rig](https://github.com/r-lib/rig), in a background job; rig itself is downloaded when it is not already available. When the renv library of a project is empty, RStudio offers to run `renv::restore()`. The check can be disabled in Global Options > Packages. | ||
| - ([#18803](https://github.com/rstudio/rstudio/issues/18803)): RStudio Desktop now logs detailed renderer, GPU, and utility process failures to help diagnose crashes. |
There was a problem hiding this comment.
The merge from main (0e823c3) appears to have kept the branch's old copy of this section. main cleared these entries in the 2026.10.0 branch update (3f4eefd): its ### New list is just -. This diff adds them back: 27 entries besides #12622, with #18692 and #18803 each appearing twice. Only the #12622 line should remain.
| #' The path to the project's renv lockfile, found as renv finds it: an | ||
| #' RENV_PATHS_LOCKFILE override (a trailing slash names a directory holding | ||
| #' renv.lock), else the lockfile of the active profile. | ||
| .rs.addFunction("renv.lockfilePath", function(project) |
There was a problem hiding this comment.
This leaves out RENV_PATHS_RENV. renv resolves the lockfile as dirname(renv_paths_renv(project))/renv.lock, and renv_paths_renv follows that variable. So with RENV_PATHS_RENV=foo/renv in the project's .Renviron, renv uses <project>/foo/renv.lock while this reads <project>/renv.lock.
renv::paths$lockfile(project = ) is exported (checked in renv 1.2.4) and covers RENV_PATHS_LOCKFILE, profiles and RENV_PATHS_RENV. Could it be used when renv is loadable, with this function kept only as the fallback?
There was a problem hiding this comment.
Fixed in 33aa145. .rs.renv.lockfilePath now uses renv::paths$lockfile(project = ) when renv is active; the fallback (renv not active, or too old to export it) mirrors renv's layout and honors RENV_PATHS_RENV too, since renv's resolver ignores the renv/profile file until the project is loaded. A new test checks that the two agree across profile / RENV_PATHS_RENV / RENV_PATHS_LOCKFILE combinations.
| #' rig makes a version "orthogonal" by rewriting those paths to its own | ||
| #' directory (see 'rig system make-orthogonal'); the launcher script tells | ||
| #' whether that happened. Other installations are always orthogonal. | ||
| .rs.addFunction("rInstallations.isOrthogonal", function(home) |
There was a problem hiding this comment.
The framework's Current version is reported as non-orthogonal too: its bin/R names R.framework/Resources, which already resolves to Current itself. rig's is_orthogonal makes the same check, so this matches rig. Still, switching to Current would work without changes.
Scenario: on macOS, switch project A to 4.4 (the switch persists in the desktop env for later sessions), then open project B whose lockfile asks for the Current version. RStudio asks for administrator authorization to edit /Library/Frameworks, and setPendingRVersion (gwt-callback.ts:1339) refuses the switch if the user declines. Exempting the version that Versions/Current points to would avoid the prompt. I haven't reproduced this; I had no framework install to test with.
There was a problem hiding this comment.
Reproduced here (Current -> 4.6, whose bin/R names the shared Resources). Fixed in 33aa145: both the R check and isOrthogonal() in r-framework.ts now treat the version Current resolves to as orthogonal, so it gets a plain switch and setPendingRVersion accepts it. Tested on both sides.
| if (!installed.isObject()) | ||
| { | ||
| ok = false; | ||
| log("R " + version_ + " was not found after installation\n"); |
There was a problem hiding this comment.
When rig add succeeds but the lookup doesn't find the new R, ok becomes false but error stays "". The job status reads "failed", and the client gets an empty error, so RenvRVersionManager shows the generic rInstallFailed message with no reason. Setting error to the "was not found after installation" text here would show the user why.
There was a problem hiding this comment.
Fixed in 33aa145: error now carries "R was not found after installation", so the client shows it.
| { | ||
| # a rename can fail across filesystems; fall back to a copy | ||
| dir.create(root, recursive = TRUE, showWarnings = FALSE) | ||
| file.copy(list.files(staging, full.names = TRUE), root, recursive = TRUE) |
There was a problem hiding this comment.
The result of file.copy isn't checked. On Linux with /tmp on tmpfs, the rename above always fails across filesystems, so this fallback is the normal path there. If the copy also fails (permissions, disk full), the function still returns the path of a rig binary that doesn't exist. The C++ side then logs "rig installed to ..." and rig add fails with a spawn error. Suggest stop()ing here when the copy fails.
There was a problem hiding this comment.
Fixed in 33aa145: the fallback stops when the install root can't be created or the copy fails (and the rename no longer warns on its way to the fallback).
| #' itself), as it does right after switching to a different version of R. | ||
| .rs.addFunction("renv.projectLibraryIsEmpty", function(project) | ||
| { | ||
| library <- .rs.tryCatch(renv:::renv_paths_library(project = project)) |
There was a problem hiding this comment.
Any error here is treated as "empty", which produces a restore prompt. If renv_paths_library errors, the "library is empty" bar appears on every start, Restart R and refresh, whatever the library contains. The trigger is narrow, since lines 91 and 159 already call the same internal, but returning FALSE on error (or using the exported renv::paths$library()) would avoid a false prompt.
There was a problem hiding this comment.
Fixed in 33aa145: an error locating the library now returns FALSE, so no restore is offered on a guess. Added a test for the empty / renv-only / populated cases.
| RVersionInstall installed = data.installed; | ||
| if (installed != null) | ||
| { | ||
| globalDisplay_.showWarningBar( |
There was a problem hiding this comment.
The warning bar holds one message at a time, so this replaces whatever warning is already showing. It fires about a second after startup and again on reconnect. That can overwrite startup warnings such as the project encoding fallback (SessionProjectContext.cpp:1121), the Quarto version warnings (SessionQuarto.cpp:158 and 176) and quota warnings (Workbench.java:330), and they don't come back. The restore prompt also returns after every refresh, even once the user has dismissed it.
There was a problem hiding this comment.
Agreed that this is a real limitation, but it is one of the single-slot WarningBar rather than of this check: the encoding, Quarto and quota warnings overwrite each other the same way today, and hiding this one behind an informational warning would bury the only actionable one. I'd rather give the WarningBar several messages (which would also let a dismissed restore prompt stay dismissed) than special-case it here; filed as #19108.
| } | ||
|
|
||
| logger().logInfo(`Switching to R: ${rPath}`); | ||
| const error = prepareEnvironment(rPath); |
There was a problem hiding this comment.
On Windows, prepareEnvironment only prepends the new R's bin directory to PATH (detect-r.ts:288), so the previous R's directory stays behind it: R-4.4\bin\x64;R-4.5\bin\x64;.... The new R comes first, so the effect is limited to DLLs or tools that only the old directory has, and PATH grows by one entry per switch. kUserLdLibraryPath already handles the same leftover for LD/DYLD paths; PATH could be rebuilt from the launch-time value the same way.
There was a problem hiding this comment.
Fixed in 33aa145: PATH is rebuilt from the launch-time value (as kUserLdLibraryPath already does), so a switch replaces the previous R's directory instead of stacking in front of it. Unit test added.
| void onClientInit() | ||
| { | ||
| if (s_sessionStarted) | ||
| scheduleProjectRVersionCheck(); |
There was a problem hiding this comment.
With rig installed, each desktop mismatch check runs rig --version, rig list --admin and rig list --user (plus R RHOME when no home can be derived) synchronously on the R thread. That happens at startup, after Restart R and on every client reconnect, with nothing cached. Caching the rig path and the installation list per session, or looking them up only when the user clicks Switch/Install, would keep reloads from blocking the console.
There was a problem hiding this comment.
Partly: rig only runs on desktop and only once the versions already mismatch, so a project on the right R never pays it and the server never runs rig (about 0.35s per check here). 33aa145 adds the part worth having: a reconnecting client reuses the list the session already made, while startup and Restart R still list afresh, so an R installed by hand is picked up. The install job's own lookup refreshes too.
| boost::function<void(StepCallback)> run; | ||
| }; | ||
|
|
||
| class RInstallJob : public boost::enable_shared_from_this<RInstallJob> |
There was a problem hiding this comment.
There are no tests for this class. Not covered: checksum mismatch, a URL with no known checksum, stopping before or during a step, a step that fails synchronously, and the "already in progress" rejection. verifyArchive is the only check on a downloaded binary that RStudio then runs, so a regression that skips it or inverts its result would pass the current R, desktop and e2e tests.
There was a problem hiding this comment.
33aa145 moves the digest check into verifyArchiveDigest() and adds gtests for a matching digest (either case), a mismatch, an unknown digest and an unreadable archive. The lifecycle cases (stop before/during a step, a step failing synchronously, the in-progress rejection) need a fake rig plus a pumped process supervisor and R in the test; filed as #19109 rather than growing this PR further.
…n-switch # Conflicts: # src/node/desktop/src/main/detect-r.ts
- find the renv lockfile as renv itself does: renv::paths$lockfile() once renv is active, else a resolver that also honors RENV_PATHS_RENV - don't report the renv library as empty (and offer a restore) when its location can't be determined - treat the macOS framework's current version as orthogonal (R and desktop), so switching to it needs no administrator prompt - say why an installation failed when rig succeeds but the new R isn't found afterwards - fail the rig install when the copy fallback fails instead of returning a path that doesn't exist - rebuild PATH from the launch-time value when switching R on Windows - reuse the session's list of installed R versions when a client reconnects; startup and Restart R still list afresh - move the archive digest check into verifyArchiveDigest() and add gtests for it
| } | ||
|
|
||
| // queried in the background: R can take seconds to start | ||
| const [, error] = await detectREnvironmentAsync(rPath); |
There was a problem hiding this comment.
Low severity. The on-disk R-environment cache from #19030 (merged in c570780) keeps a single query entry (r-environment-cache.ts:74). This query ends in persistEnvironment, so it replaces that entry with the R being switched to:
- macOS/Linux: the switch isn't stored, so the next launch queries the default R, finds the switched R's entry, and misses.
- Windows: the switched R is stored, but its entry is stamped with PATH =
<previous R bin>;<launch PATH>. That's becauserQueryEnvironment(detect-r.ts:520) resets the LD/DYLD paths to their launch values but not PATH. The next launch's PATH is the launch value, so the stamp differs and it misses there too.
The cost is one slow R query on the launch after each switch. Using kUserPath for the query's PATH on Windows would make that entry reusable. On macOS/Linux, not writing the switch query to disk would keep the default R's entry.
|
|
||
| ### New | ||
| - ([#12622](https://github.com/rstudio/rstudio/issues/12622)): RStudio Desktop now warns when a project asks for a different version of R than the one running (as recorded in its renv lockfile, or in the project file), and offers to switch to it. A version that is not installed is installed first, via [rig](https://github.com/r-lib/rig), in a background job; rig itself is downloaded when it is not already available. When the renv library of a project is empty, RStudio offers to run `renv::restore()`. The check can be disabled in Global Options > Packages. | ||
| - |
Intent
When a project asks for a different version of R than the one running, tell the user and make switching a single click, installing that R first when it is missing. The request comes from the project's
renv.lock(R.Version), or from an explicitRVersionin the.Rproj, which wins when set. Only the major.minor is compared, matching renv's own load-time check.Fixes #12622.
Approach
SessionRenv.cpp/.R): once a new session is idle after startup (or one resumed from a suspend for restart, i.e. Restart R, as renv's own check runs again then;RInitInfonow records which kind of suspend a resumed session came from), and again whenever a client reconnects to the running session (e.g. a browser refresh), read the requested version (the lockfile is found as renv finds it, including profiles andRENV_PATHS_LOCKFILEdirectory overrides; anything that isn't a version number is ignored), compare it with the running R, and fireproject_r_version_mismatch(which also reports an R installation in progress, so a reloaded page picks up waiting for it). Only the minimum supported R version is enforced (the maximum is a "tested with" bound), judged by the R that would actually run. When the versions agree but the renv library is empty and the lockfile records packages, firerenv_restore_prompt.SessionRig.R/.cpp/.hpp): installed versions come from rig (both modes) plus the platform's standard locations, so R installed without rig is found too; homes are derived from the layout without running R, and native arm64 builds are preferred on Apple silicon (read fromlibR.dylib's Mach-O header). Installing runs in a Background Jobs job: download rig with curl when missing (a rig older than the pinned 0.10.0 is passed over), verify it against pinned SHA-256 digests, extract it, thenrig add <version> --user(admin mode needs sudo, which a session child can't answer). Completion is reported throughr_install_completed; the job can be stopped at any point. Installing is refused outside desktop mode.RenvRVersionManagershows the warning bar, now with an action link (WarningBar.setAction); everything substituted into its HTML is escaped. The switch reuses the quit path Workbench already uses (quit_sessionwith anRVersionSpec). Once the quit is going ahead, the newsetPendingRVersionbridge call has the desktop check that the R runs (in the background) and hold on to it for the relaunch; a quit that then fails clears it. The bar and its offer stay up until the quit goes ahead, and a failed switch shows why, with the offer to try again. A new pref,check_project_r_version(Global Options > Packages), disables the check. Server editions show the bar without an action.launchNextSessionprepares the environment for the pending R and picks the rsession build matching it on every launch (arm64/x86_64 on macOS, UCRT/i386 on Windows), since a switch can call for another one. On Windows the switch is stored as the Choose R dialog stores a choice (clearing the use-default flags), once a session has started with it, so it holds for later launches and can be changed back there. On macOS and Linux nothing is stored: the switch lasts until RStudio quits, and the bar offers it again on the next launch if the project still asks for it.R.framework/Versions/<v>/Resources/bin/Rlauncher hard-codes the framework's Current R as its home, so querying a versioned install through it (and switching to it) silently yields the default R.detect-r.tsnow takes the launcher's steps with the install's ownR_HOME(source itsetc/ldpaths, then runbin/exec/R), which is also what selects thelibR.dylibrsession loads. Every R is also queried with the library path RStudio was launched with, so after a switch the previous R's library directory no longer leads the session's library path.bin/R(andRenviron,fonts.conf,Makeconf) pointing at the framework's sharedResources, i.e. the Current version. Even with rsession switched, every R process it starts (R CMD INSTALL,renv::restore(), callr) would run Current. The session flags such versions; switching to one first asks to update it the wayrig system make-orthogonaldoes (the prompt says it affects all users of the Mac). The desktop applies the change (r-framework.ts) directly when the files are writable (the installer makes them writable by the admin group), otherwise through macOS's administrator authorization dialog, and it refuses to switch to a version that is still non-orthogonal.Verification
rstudio-tests --scope r --filter "rig|renv|linter": 200 pass (test-rig.Ris new; lockfile and version-check tests added totest-renv.R).npm test(480, includingr-framework.test.ts, which updates a fake framework tree),npm run lint,npm run typecheck.ant draftbuilds.tests/projects/renv_r_version_switch.test.ts:PW_ALLOW_R_FRAMEWORK_UPDATE=1, as it edits a system-wide installation);Rstill runs 4.6.1; the edited files keep theirroot:adminownership) and switched to it, and a second run switched to the updated 4.5 and declined the update of 4.4. The files were writable by the admin group there, so the administrator-authorization path has not been exercised.Not in this PR