4

Attempting to switch from R-Studio to VSCode in Windows. 2 questions:

  1. How do I allow R scripts in VS Code to send code to the R terminals in VS Code. I currently get the "command r.executeInTerminal not found". There's a screenshot of what that looks like here.
  2. Am I using the wrong file path for radian?

Here are the exact steps I've taken so other rookies might be a little quicker than I was.

I installed the latest version of python (3.10.6; don't install from windows store, but from here), and R (4.2.1). I then installed radian using the following command following advice from here inside a Windows PowerShell terminal within VSCode:

py -m pip install -U radian

I then found the install path (following advice here) by typing, in the same place:

py -m pip show radian 

Output: Location: c:\users\louis\appdata\local\programs\python\python310\lib\site-packages

In file explorer I copied the path into the search bar, moved to the radian folder, hit the copy path button in the top left, then added the path to the R settings page to my user settings (JSON), but it didn't work.

I decided to stop trying to use radian and keep the r.rterm.windows directly to the R.exe file path. I found this file path using the following in RStudio:

R.home("bin") # [1] "C:/PROGRA~1/R/R-42~1.1/bin/x64"

Note to the lost: You have to reverse the slashes to find the file in windows, so this for me was "C:\PROGRA~1\R\R-42~1.1\bin\x64".

You can then paste the file path into your file explorer and find the R.exe file. I then was able to connect R to my VS Code terminal in the settings page, but scripts don't send information to the terminal. This means hitting ctrl+entr with the cursor in the temp.R file leads to the message: "command r.executreInTerminal not found".

There's a screenshot of what that looks like here.

My user settings (JSON) now look like this:

{
    "python.defaultInterpreterPath": "C:\\Users\\louis\\AppData\\Local\\Programs\\Python\\Python310\\python.exe",
    "files.associations": {
        "*.rmd": "markdown"
    },
        // R Options
        "r.rpath.windows": "C:\\Program Files\\R\\R-4.2.1\\bin\\R.exe",
        "r.rterm.windows": "C:\\Program Files\\R\\R-4.2.1\\bin\\R.exe",
        "r.terminalPath": "C:\\Program Files\\R\\R-4.2.1\\bin\\R.exe"
        "r.lsp.path": "C:\\Program Files\\R\\R-4.2.1\\bin\\R.exe",
        "r.lsp.debug": true,
        "r.lsp.diagnostics": true,
        "r.alwaysUseActiveTerminal": true,
        "r.sessionWatcher": true, 
        "r.bracketedPaste": true,
}

Where's the error? Why don't the two panels talk to each other? Why is this like pulling teeth?

Louis Shaw
  • 51
  • 1
  • 4
  • What happens if you change your `r.rterm.windows` from your `R.exe` path to your `radian.exe` path? – coip Sep 14 '22 at 15:51

1 Answers1

6

It looks like you might have settings from two different VS Code R extensions (vscode-R and R Tools). Try removing the keybinding for r.executeInTerminal (which is an R Tools command). Then Ctrl-Enter should execute r.runSelection (which is a vscode-R command).

andycraig
  • 710
  • 5
  • 18
  • Thank you for the help. Rtools isn't loading correctly in VSCode. "Couldn't start client R Tools" I installed it following the advice here (https://cran.r-project.org/bin/windows/Rtools/rtools42/rtools.html) and here (https://www.youtube.com/watch?v=hBTObNFFkhs). I'm happy that Rtools is loaded correctly, but now I have the following error. [Error - 18:03:25] Starting client failed Launching server using command dotnet failed. – Louis Shaw Sep 02 '22 at 17:06
  • 1
    Looks like you've installed Rtools, which is a build tool for R. I was talking about the VS Code extension R Tools: https://marketplace.visualstudio.com/items?itemName=Mikhail-Arkhipov.r I don't recommend having both vscode-R and R Tools installed because they do many of the same things in different ways and you'll likely experience conflicts with settings etc. Choose either [vscode-R](https://marketplace.visualstudio.com/items?itemName=REditorSupport.r) or [R Tools](https://marketplace.visualstudio.com/items?itemName=Mikhail-Arkhipov.r). – andycraig Sep 02 '22 at 23:08
  • By the way, looking at your screenshot you do already have vscode-R installed. – andycraig Sep 02 '22 at 23:35
  • 1
    Thank you for all the help, I really appreciate it. I'll uninstall RTools and go with the VS code version. Hopefully you won't hear from me again on here, but a huge thank you for taking the time! – Louis Shaw Sep 04 '22 at 20:12