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

Viewed 10556

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

4 Answers

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. Restart VSC and the error should go away.

enter image description here

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.

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

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.

Related