Louis Shaw
Louis Shaw

Reputation: 71

Setting up R to work with Visual Studio Code from scratch - "command `r.executeInTerminal` not found"

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?

Upvotes: 6

Views: 13475

Answers (2)

Scheggia
Scheggia

Reputation: 43

I have had the same issue. I have solved installed the newest version of .net runtime https://dotnet.microsoft.com/it-it/download/dotnet

That it because of if you click on the allert (the bell). Click on the error and you can get the reason why you have gotten the error. In my case i had a old version of .NET runtime.

Then i have restarted the operating system and the command ctrl+enter was working and i was able to send code to the R terminals in VS Code.

Upvotes: 0

andycraig
andycraig

Reputation: 870

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).

Upvotes: 10

Related Questions