Skip to content

Contribute R path, home, etc. to terminals#14886

Open
jmcphers wants to merge 1 commit into
mainfrom
feature/terminal-console-r-version
Open

Contribute R path, home, etc. to terminals#14886
jmcphers wants to merge 1 commit into
mainfrom
feature/terminal-console-r-version

Conversation

@jmcphers

Copy link
Copy Markdown
Collaborator

Fixes #7403

Summary

Terminals launched from Positron now use the same R installation as the active console. Previously the terminal always resolved R/Rscript from the system PATH, so on a machine with multiple R versions the terminal ran a different R than the one selected in the console. This also broke extensions that start R in a terminal to do background work (Quarto Preview, Shiny Run App, etc.), since those tasks ran against the system default R rather than the version the user selected.

The R extension now contributes terminal environment variables that point at the active console's R installation:

  • PATH - prepends the directory of the selected R binary so R, Rscript, and anything that shells out to them resolve to the selected version (mirrors how rig exposes a selected R via symlinks on PATH).
  • R_HOME - set so tools that read it directly find the selected installation.
  • QUARTO_R - points at the Rscript directory so quarto render and the bundled Quarto extension use the selected R.
image

The contributed environment is kept in sync as sessions are created, restored, and as the foreground console switches between R versions. When multiple R consoles run different versions, the most recently focused one wins; this ambiguity is expected and documented.

DYLD_LIBRARY_PATH / LD_LIBRARY_PATH are intentionally not contributed, even though the Ark kernel sets them: those affect dynamic linking for every program in the terminal (not just R) and can cause unrelated tools to load R's bundled libraries. R's own launcher scripts already configure their library paths, so they aren't needed for R to work from the terminal.

Note

This does not attempt to address existing issues around environment modules and terminals; if R requires a module load to run, it still may not work in the terminal even after this change. That issue is tracked in #12850.

Release Notes

New Features

  • N/A

Bug Fixes

Validation Steps

@:quarto @:apps @:console

On a system with multiple R versions installed:

  1. Select an R version that is not first on your system PATH as the console interpreter.
  2. Open a new Terminal and run R --version (and Rscript --version) - it should report the version selected in the console, not the system default.
  3. Run Rscript -e 'R.home()' and confirm R_HOME points at the selected installation; check echo $QUARTO_R (or %QUARTO_R% on Windows) points at that R's bin directory.
  4. Switch the foreground console to a different R version, open another Terminal, and confirm it picks up the newly selected version.

Unit coverage for the environment-mutation logic (PATH/R_HOME/QUARTO_R across posix and win32) lives in extensions/positron-r/src/test/terminal-environment.unit.test.ts.

@jmcphers jmcphers requested a review from jennybc July 15, 2026 17:45
@github-actions

Copy link
Copy Markdown

E2E Tests 🚀
This PR will run tests tagged with: @:critical @:quarto @:apps @:console @:ark

Why these tags?
Tag Source
@:critical Always runs (required)
@:quarto PR description
@:apps PR description
@:console PR description
@:ark Changed files

More on automatic tags from changed files.

readme  valid tags

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.

R version in Terminal doesn't match R version in Console (PATH, QUARTO_R, R_HOME, etc.)

1 participant