R versions
How VS Code finds R
Nothing in my synced settings names an R version or a path:
r.consolePathis"radian", found onPATH.r.executablePathis not set, so vscode-R usesR.exeonPATH, which is rig’s shortcut inC:\Program Files\R\bin.- The R Debugger extension reads only the old
r.rpath.windows. That is not set either, so it also usesR.exeonPATH. vscode-R shows a one-time warning about this whenever R Debugger is installed; without a project pin there is nothing to do. - radian also starts the R on
PATH, unlessR_HOMEis set or--r-binaryis given.
So the R version is whatever rig default says on that machine. The settings stay identical everywhere, which is what lets Settings Sync carry them.
Switch R for the whole machine
rig list # installed versions; * marks the default
rig add release # install the newest release (or: rig add 4.5)
rig default 4.6.2 # use it everywhereThen open a new R terminal. No VS Code change is needed. Remember that a new R version starts with an empty package library: install the R packages for it.
Pin one project to a version
Sometimes a project needs an older R, for example one whose renv.lock was made with R 4.5.1. The pin goes into that project’s workspace settings, .vscode/settings.json, which override the profile.
With the R Version Switcher extension
I wrote (well, vibe-coded) a small extension for this: R Version Switcher. It works with rig and the R extension. It is not on the Marketplace; install the .vsix from its latest release with code --install-extension r-version-switcher-1.2.0.vsix --profile R. Its commands:
| Command | What it does |
|---|---|
| R: Switch Version | Pick an installed R version for this workspace. The list marks the current one, the system default and the one in renv.lock. |
| R: Use R Version from renv.lock | Switch to the version recorded in renv.lock; offers to install it (or the newest patch of the same minor version) if it is missing. |
| R: Show Current Version | The workspace’s R version and path, and whether the path is valid. |
| R: Add Version / R: Remove Version | rig add / rig rm, run as a VS Code task so you see the output. |
| R: Set System Default Version | rig default, without touching the workspace. |
| R: Install Rtools | Installs the Rtools versions your R versions need but do not have. |
A status bar item shows the workspace’s R version and turns yellow when it differs from renv.lock. Click it to switch. That pairs well with the project template, which uses renv.
The extension writes the same settings as the manual method below, using rig’s version link when it exists, including r.rpath.windows when R Debugger is installed. Restart the R terminal after switching.
By hand
First, once per machine, create the version-named shortcuts:
rig system make-links # creates R-4.6.2.exe, R-4.5.1.exe, ... in C:\Program Files\R\binThen in the project’s .vscode/settings.json:
{
"r.executablePath": "R-4.5.1.exe",
"r.consoleArgs": ["--no-save", "--no-restore", "--r-binary=R-4.5.1.exe"],
"r.rpath.windows": "R-4.5.1.exe"
}r.executablePathis the R that vscode-R uses for the language server, help and the workspace viewer.r.consoleArgsis passed to radian.--r-binarymakes radian start that R. The first two arguments are vscode-R’s default, which the workspace value would otherwise replace.r.rpath.windowsis for the R Debugger extension, which reads only this older setting. Without it, the debugger runs the default R instead of the pinned one. vscode-R marks the setting as deprecated, but asks to keep it, with the same value asr.executablePath, while R Debugger is installed. Leave it out if you do not use R Debugger.R-4.5.1.exeis found onPATH, so the file contains no user name and no install path. It works on every machine that has R 4.5.1 through rig, so the file can be committed.- Keep the
.exe. vscode-R adds.exeonly to names without an extension, andR-4.5.1looks like it has one (.1), so without it vscode-R does not find R. radian accepts both. - A full path such as
C:\\Program Files\\R\\R-4.5.1\\bin\\R.exealso works and contains no user name, but it is Windows-only.
To check which R a terminal really runs: R.version.string in the console, or radian --r-binary=R-4.5.1 --version in PowerShell.