Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing R version in VS Code

I am trying to use VSCode after having used RStudio for a long time. I have multiple versions of R installed on my machine. Usually, I use the most recent version but occasionally I want to switch to use an older version. In R Studio, it is easy to change to a previous version but I cannot figure out how to change the version of R being used in VSCode.

like image 556
L10Yn Avatar asked Feb 14 '26 03:02

L10Yn


2 Answers

You can access the language settings by clicking the language in the lower right hand corner of the window:

enter image description here

This will open language options in the command palette:

enter image description here

If you click "Configure 'R' language based settings...", settings.json will open. There should be a parameter already included called "r.rterm.windows". You can update this to point to the version of R you want to use. The next time you open a new terminal, it should use this setting.

enter image description here

like image 164
nrp1000 Avatar answered Feb 15 '26 16:02

nrp1000


View > Command Palette (Ctrl+Shift+P) > Preferences: Open User Settings (JSON)

and in there (file settings.json) change the paths for r.rpath.windows, r.lsp.path and --r-binary

Don't forget to add Rscript.exe to path: see here

My file settings.json is like below:

{
    "window.zoomLevel": 1,
    "[python]": {
        "editor.formatOnType": true
    },
    "python.defaultInterpreterPath": "C:\\Users\\500596972\\AppData\\Local\\Programs\\Python\\Python310\\python.exe",
    "security.workspace.trust.untrustedFiles": "open",
    "workbench.colorTheme": "Default Dark+",
    "terminal.integrated.enableMultiLinePasteWarning": false,
    // R Options
    "r.rterm.windows": "C:\\Users\\500596972\\AppData\\Local\\Programs\\Python\\Python310\\Scripts\\radian.exe",
    "r.rpath.windows": "C:\\Program Files\\R\\R-4.4.0\\bin\\x64\\R.exe",
    "r.lsp.path": "C:\\Program Files\\R\\R-4.4.0\\bin\\x64\\R.exe",
    "r.lsp.debug": true,
    "r.lsp.diagnostics": true,
    "r.alwaysUseActiveTerminal": true,
    "r.plot.useHttpgd": true,
    "r.rterm.option": [
         "--no-save",
         "--no-restore",
         "--r-binary=C:\\Program Files\\R\\R-4.4.0\\bin\\x64\\R.exe"
    ],
    "r.bracketedPaste": true,
    "r.sessionWatcher": true,
    //
    // Global Options
    "files.defaultLanguage": "r",
    "jupyter.interactiveWindow.creationMode": "perFile",
    "jupyter.askForKernelRestart": false,
}


like image 42
alexyshr Avatar answered Feb 15 '26 17:02

alexyshr



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!