I am trying to use Visual Studio for R for the first time, and am having a hard time starting.
I have installed VSCode as a binary on my Windows machine (needed because of corporate machine).
My R executables are in my documents folder (also because I'm on a corporate machine).
I have downloaded R
and R Debugger
extensions in VSCode. *I could not find R LSP Client
, even though tutorials from 2020 showed that it was necessary.
I have installed languageserver in my R client, and have also done pip install radian.
My settings.json looks like this:
"r.rpath.windows": "C:\\Users\\XXXXX\\Documents\\R\\R-4.0.3\\bin\\x64\\R.exe",
"r.bracketedPaste": true,
"r.rterm.windows": "C:\\Users\\XXXXX\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python39\\Scripts\\radian.exe",
"r.lsp.debug": true,
"r.lsp.diagnostics": true,
"r.rterm.option": [
"--no-save",
"--no-restore",
"--r-binary=C:\\Users\\XXXX\\Documents\\R\\R-4.0.3\\bin\\x64\\R.exe"
]
Somehow each time I execute code, it shows:
[Running] Rscript "c:\Users\XXXX\code\R\tempCodeRunnerFile.R"
'Rscript' is not recognized as an internal or external command,
operable program or batch file.
What am I doing wrong? This is my first time using VSCode, and I've tried looking across multiple stack overflow questions and URLs to no avail. Thanks in advance for your help!
Note--see comments in solution, but I ended up copying radian.exe into a new folder and resetting the path there in the json file. And importantly, in VSCode, you cannot use Ctrl Alt N for R. You must use Alt Enter
CodePudding user response:
Step 1: Ensure R is setup right:
In your JSON settings, change r.rpath.windows
and --r-binary
from
"C:\\Users\\XXXXX\\Documents\\R\\R-4.0.3\\bin\\x64\\R.exe"
to
"C:\\Users\\XXXXX\\Documents\\R\\R-4.0.3\\bin\\R.exe"
(That is, drop the \\x64
--and don't worry, VSCode should still open 64-bit R even with these changes).
Step 2: Fix the issue of running an R Script from the Editor:
In your JSON settings, add the following line:
"r.alwaysUseActiveTerminal": true,
Step 3: Fix the Radian path
Double check your path location for Radian under r.rterm.windows
. Try changing it to:
"C:\\Users\\XXXXX\\AppData\\Local\\Microsoft\\WindowsApps\\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\\radian.exe"
After that, save the changes and then restart VSCode.