John Smith
John Smith

Reputation: 2886

Setting Up Visual Studio code to work with R - "win32 can't use R"

I am trying to set up R to work with Visual Studio code. When i execute a line with the keys CTRL+ENTER I get the error "win32 can't use R".

I am following the advice laid out in this medium post where i have managed to install all the extensions but am unsure where to apply point "4. Finally add these lines in the settings.json of your editor"

I have seen the this post which describes (I think) how to update the settings.JSON but to be honest im not sure where and if this is the correct place to add the lines in the original post.

The JSON file on my PC looks like the below

{
    "[json]": {
    
        "editor.quickSuggestions": {
            "strings": true
        },
        "editor.suggest.insertMode": "replace",
        "gitlens.codeLens.scopes": [
            "document"
        ]
    }
}

Could someone point me in the right direction

Thanks

Upvotes: 22

Views: 55912

Answers (5)

Andrew
Andrew

Reputation: 744

When I had this error, I did the following with Win10Pro (20H2) and VSC 1.53.0-insider

  1. Locate your R.exe location. Mine is at C:\Program Files\R\R-3.6.2\bin\x64\R.exe
  2. Open VSC, once loaded, press Ctrl+, to open your settings. In "Search Settings" type "R".
  3. In the left column under "Commonly Used" scroll down to Extensions > R
  4. In the settings for "R", scroll down to R > Rpath: Windows
  5. Enter the RPath determined in #1 above, then Ctrl+S to save. Or when you close the "Settings" pane, I think it should save.
  6. You may have to do the above with Rterm.exe as well.
  7. Restart VSC and the error should go away.

enter image description here

Upvotes: 50

Even changing both settings in the way @Dr_Be mentions, I still couldn't run R code. This is the error I got:

Cannot find R client at "C:\Program Files\R\R-4.2.2\bin\x64\Rterm.exe". Please check r.rterm setting.

The reason for these errors was that I was pasting the filepath to both R.exe and Rterm.exe (as the previous answers point out) with quotes at the beginning and ending of the filepath, as you would when using CLI. Just paste them without the quotes and it should work.

Upvotes: 3

Brad
Brad

Reputation: 680

File -> Preferences -> Settings

Rpath: C:\Users\xxxxx\AppData\Local\Programs\R\R-4.2.1\bin\R.exe

Rterm: C:\Users\xxxxx\AppData\Local\Programs\R\R-4.2.1\bin\R.exe

Then install at least one library using RGui (which is outside of VScode).

Restart VScode will then it will recognize the R library path.

Upvotes: 9

Ctrl-Zed
Ctrl-Zed

Reputation: 687

My fix to resolve 'win32 can't use R' in VSCode was to uninstall R and install without 32-bit at all.

When installing R, there is the option to install 32-bit and 64-bit. I de-selected 32-bit, and now it works fine.

As a noob, my first install included both 32-bit AND 64-bit (although it was installed into the 64-bit Program Files)...

Upvotes: 0

Dr_Be
Dr_Be

Reputation: 252

Just to point out that @Andrew was correct with his last comment to his answer. At least on my Windows installation I had to put both paths in order to get rid of the "win32 can't use R" error, i.e. the path to R.exe shown in the screenshot plus the path to Rterm.exe at the entry R > Rterm: Windows. Without the second entry the error persisted in my case.

Upvotes: 10

Related Questions