Skip to content

Offer R install and switch choices with destination confirmation - #19158

Merged
kevinushey merged 9 commits into
mainfrom
codex/renv-install-confirmation
Nov 2, 2026
Merged

kevinushey merged 9 commits into
mainfrom
codex/renv-install-confirmation

Conversation

@kevinushey

Copy link
Copy Markdown
Collaborator

Intent

When a project requests R 4.5.3 but only R 4.5.2 is installed, the Console now offers both Install and Switch to R 4.5.3 and Switch to R 4.5.2. Choosing installation first opens a dialog where the user can confirm, edit, or browse for the installation folder. Cancel leaves the Console offer available and starts no installation.

Approach

  • Show project R-version and renv restore notices in the Console, with theme-aware buttons, wrapping layouts, dismissal, and screen-reader announcements.
  • Show only the switch action when an installed version satisfies the request, including major/minor requests.
  • Fetch rig's default user installation folder and validate the selected path before starting a background job. Pass the confirmed folder to the installer without changing the session environment or rig configuration.
  • Remember custom installation roots across restarts, and locate the requested R in the selected folder when installation completes.

Automated Tests

  • Added R tests for default folders, path validation, custom-root discovery, and exact-version selection. The focused test-rig.R suite passes with four platform skips using a standalone source-backed harness.
  • Added desktop end-to-end coverage for both buttons, editing/clearing the folder, canceling without an install request, and switching to the nearby installed version. Focused TypeScript checking passes.
  • GWT draft compilation and focused C++ compilation pass. Rendered previews were checked for layout and light/dark theme styling.
  • Full desktop end-to-end execution and the native session test runner remain unverified because the local app encountered a locked native module and a session startup crash.

QA Notes

Verify an exact installed match, a missing patch with a nearby installed match, and a missing version without a nearby match. Check the installation dialog in light and dark themes, keyboard navigation, Browse, empty/invalid folders, cancellation, and installation into a custom folder containing spaces. After installation, confirm RStudio restarts with the requested R and can discover it again after a later restart.

Documentation

Added a release note in NEWS.md. The dialog explains the per-user installation folder and the restart after installation; no separate guide changes are included.

Checklist

  • Includes an entry in NEWS.md.
  • Updated UI meets accessibility standards (labels and announcements included; full app audit pending).
  • A reviewer is assigned.
  • All local unit tests pass (focused checks pass; full native runner blocked as noted above).

@github-actions

github-actions Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

RStudio E2E - all platforms

All tests passed!

#################### 100% pass rate

Passed Failed Skipped Flaky
4795 0 233 2
Platform ✅ Passed ❌ Failed ⚠️ Skipped 🔁 Flaky
✅ auth-teardown 4 0 16 0
✅ desktop-linux 1199 0 44 1
✅ desktop-macos 1206 0 39 0
✅ desktop-windows 1198 0 51 1
✅ server-linux 1140 0 51 0
✅ setup 48 0 32 0
View / download the full report

View report online -- opens in the browser, no download needed. Available for 14 days.

Download playwright-report.zip -- extract and open index.html

Includes screenshots, traces, and step-by-step details for every test. Expires in 15 days.


All platforms - commit b6b42fc517437e2b064f955f1345f913806276af - Run #1899

…nfirmation

# Conflicts:
#	e2e/rstudio/tests/projects/renv_r_version_switch.test.ts
#	src/cpp/session/modules/SessionRig.R
#	src/cpp/session/modules/SessionRig.cpp
#	src/cpp/tests/testthat/test-rig.R
…nfirmation

# Conflicts:
#	src/cpp/session/modules/SessionRig.R
… while pending

- userInstallBegin's third positional parameter is launchctl, so the
  destination went there instead of 'directory'
- the destination-specific lookup skipped the cache refresh that
  findInstalledRVersion used to do, so a reload offered the install again
- editing the folder while the install request was pending re-enabled OK
- fake-rig lifecycle tests now unset an inherited RIG_R_INSTALL_DIR
- fold the NEWS entry into #12622's
Two sessions remembering different roots at once could each rewrite the
file from a stale read and drop the other's entry.
@kevinushey
kevinushey requested a review from gtritchie November 2, 2026 01:22

@gtritchie gtritchie left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments inline. None of them block merging. The closest to a bug is that the install is refused when the custom root can't be recorded (SessionRig.cpp:406); the rest are cleanup, one test gap, and one accessibility gap in the new dialog.

I checked that rig 0.11.0 respects RIG_R_INSTALL_DIR for rig system dirs and rig list, and that scanRoots matches its macOS user-mode layout. The which.max -> order() change in findInstalledRVersion is a real fix: which.max(package_version(...)) errors on R 4.3.3.

if (error)
return error;

error = r::exec::RFunction(".rs.rig.rememberInstallDir")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If .rs.rig.rememberInstallDir fails (user data dir read-only, full, or with bad permissions), this returns the error and R isn't installed at all, even though the root is only being recorded for later discovery.

Recording it before the job starts makes sense, since on macOS rig can outlive a session that crashes mid-install. But a failure here should be logged (LOG_ERROR) and the install should go ahead.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Fixed in 4663580: a failure to record the root is logged and the install goes ahead. The job still finds the new R by scanning the confirmed directory, so only later discovery would be affected.

Comment thread src/cpp/session/modules/SessionRig.R Outdated
#' Without rig (a damaged installation), use the explicit environment
#' override or its platform default. The confirmed path is always passed to
#' rig.
.rs.addFunction("rig.defaultInstallDir", function(rig = .rs.rig.find(),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When rig isn't found, this falls back to copies of rig's per-platform default roots so the dialog still has a folder to show. But RInstallJob::initialize resolves rig with the same .rs.rig.find() and fails with "rig was not found" whatever folder is chosen, so the user confirms a dialog for an install that can't run.

Simpler: have rig_get_install_dir return a "rig was not found" error when .rs.rig.find() is empty, and drop the override/APPDATA/~/.local/share/rig/r fallback and its test. That also removes a copy of rig's defaults that could drift from rig's own.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 4663580. .rs.rig.defaultInstallDir now errors with "rig was not found" when rig is absent (the client shows that in an error dialog), and the platform-default fallback and its test are gone.

Comment thread src/cpp/session/modules/SessionRig.cpp Outdated
Error lookupError = findInstalledRVersion(version_, &installed);
// later checks this session (e.g. after a reload) reuse the cached
// list of installations, which must include the new R
Error refreshError = r::exec::RFunction(".rs.rInstallations.cached")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This relists every installation synchronously (rig list --admin, rig list --user, the platform scan, every remembered root), and installedRVersion then scans the destination again. Right after this, onRInstallCompleted calls switchToR, and a user-mode install is always orthogonal, so the session usually restarts and throws the refreshed list away.

Clearing the cache instead (.rs.rInstallationsCache$installed <- NULL) covers the reload case equally well, because rInstallations.cached() relists when it's NULL, and it does no work in the common case.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switched to clearing the cache (.rs.rInstallations.clearCache()) in 4663580; the next lookup relists.

if (refreshError)
LOG_ERROR(refreshError);

Error lookupError = r::exec::RFunction(".rs.rig.installedRVersion")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This replaces the only call to the C++ findInstalledRVersion (defined further down in this file, declared in SessionRig.hpp:38). Nothing else in src/cpp calls it, so it can be removed along with its declaration.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed in 4663580, along with the declaration in SessionRig.hpp. Pro only uses installInProgress() from that header.

Comment thread src/cpp/session/modules/SessionRig.R Outdated
})

#' Read the standard rig user-mode layouts at roots selected in RStudio.
.rs.addFunction("rInstallations.scanRoots", function(roots)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This re-derives rig's user-mode layout and repeats the row-building in rInstallations.scan. rig can list a custom root itself: with rig 0.11.0, RIG_R_INSTALL_DIR=<root> rig list --user --json lists that root's versions and skips the Current alias. That's the same pattern rig.userDirs uses.

The tradeoff is one rig run per remembered root on each listing, so this is a suggestion. If you keep the scan, sharing one row-builder with rInstallations.scan would remove the duplication.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kept the scan but took the second option: scan and scanRoots now share .rs.rInstallations.rows() (4663580). Running rig per remembered root would add a process per root to every listing, and the scan is also what keeps those roots visible when rig itself is missing.


events.addHandler(ConsoleActivateEvent.TYPE, event -> activateConsole(event.getFocusWindow()));

events.addHandler(RenvRestorePromptEvent.TYPE, event ->

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The renv restore prompt was handled in RenvRVersionManager (an eager singleton, RStudioGinModule.java:311). Here it moves into the Console presenter, which now depends on RenvConstants and builds renv::restore() itself, while the R-version notices still go through RenvConsoleNoticeEvent.

Keeping onRenvRestorePrompt in RenvRVersionManager and having it call showNotice(...) would leave Console handling only RenvConsoleNoticeEvent, with all the project-notice logic in one place.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved back in a6f0e73: RenvRVersionManager handles RenvRestorePromptEvent and goes through showNotice, so Console only handles RenvConsoleNoticeEvent now.

Comment thread src/cpp/tests/testthat/test-rig.R Outdated

test_that("the default R install directory follows the platform and override", {

default <- function(...) .rs.rig.defaultInstallDir(rig = "", ...)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Every case passes rig = "", so only the fallback branch is tested. The branch that runs in practice (rig system dirs --user, checking r_root, erroring otherwise) isn't covered.

fakeRig in this file could cover a good r_root, an empty one, and rig exiting non-zero.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rewritten with fakeRig in 4663580: good r_root, the RIG_R_INSTALL_DIR override, empty r_root, rig exiting non-zero, and no rig.


contents_ = new VerticalPanel();
contents_.setWidth("440px");
contents_.add(new Label(constants_.rInstallDescription(version)));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This description (installed in its own subfolder, RStudio restarts afterwards) isn't linked to the dialog, and focus goes straight to the folder field. A screen-reader user hears the title and "Install in:", but not that confirming will restart RStudio under a different R.

ModalDialogBase.setARIADescribedBy(Element) handles this. Keep the Label in a field and call setARIADescribedBy(description.getElement()). (.claude/CLAUDE.md: "New UI should be built to conform from the start.")

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in a6f0e73 with setARIADescribedBy(description.getElement()).

…the row builder

Review follow-ups: a root that cannot be remembered no longer refuses the install; the default destination errors without rig instead of showing a folder the job could not use; the cache is cleared rather than relisted when a job finishes; the unused C++ findInstalledRVersion is removed; the scans share one row builder; and the default-directory test covers rig's own branch.
@kevinushey
kevinushey requested a review from gtritchie November 2, 2026 20:10

@gtritchie gtritchie left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All eight comments are addressed in 4663580 and a6f0e73. One optional leftover: SessionRig.hpp still includes shared_core/json/Json.hpp, which nothing in the header uses since findInstalledRVersion was removed.

@kevinushey
kevinushey merged commit 5b7b820 into main Nov 2, 2026
1 of 5 checks passed
@kevinushey
kevinushey deleted the codex/renv-install-confirmation branch November 2, 2026 22:45
kevinushey added a commit that referenced this pull request Nov 13, 2026
#19158 restored the six 2026.11 New entries after the branch update cleared them, and #19158 and #19350 then edited three of them in place to describe follow-up work. Drop the three verbatim copies, and cut the other three down to what 2026.12 adds.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants