vscode-R icon indicating copy to clipboard operation
vscode-R copied to clipboard

R language server in vscode does not work properly with conda environments

Open bk1n opened this issue 8 months ago • 1 comments

Describe the bug Currently, to set up a conda environment with R in VS Code you need to:

  1. conda create -n r443 -c conda-forge r-base=4.4.3
  2. Modify workspace JSON settings by creating a .vscode/settings.json file and modifying r.rpath.xx and r.rterm.windows to point to appropriate R executable (always R) and terminal (e.g. default R, radian)
  3. Use Python extension to do Python: Select Interpreter... - this allows the R terminal to automicatically activate the conda environment prior to running code.

Now I have a functioning R terminal that can send code from VS code editor directly to terminal. I then was getting errors such as: Failed to get list of R functions. Make sure that jsonlite is installed and r.rpath.windows points to a valid R executable. and issues with help: Couldn't show help for path: /library/stats/html/stats-package.html

Which I realised were issues with R language server.

I also was getting the error when launching vscode: R Language Server (26808) exited with exit code 3221225781

This error is associated with missing DLLs. I found from this issue that this is due to missing DLLs available when doing conda activate r443 - R language server doesn't do this and therefore doesn't work.

A fix is to add these DLLs to PATH, (normally found in /c/Users/<>/miniconda3/envs/r443/Library/bin) and confirming with where libblas.dll in base environment.

Obviously, this is not desirable and it took me ages to figure all this out. Is there a way to run conda activate r443 prior to launching R language server to expose the appropriate DLLs?

P.S. - apologies if this is better suited for languageserver issues, I thought it probably was better suited here as it's regarding the launching and management of the extension via vscode-R.

Thanks!

settings.json:

{
    "r.rpath.windows": "C:\\Users\\<>\\miniconda3\\envs\\r443\\Scripts\\R.exe",
    "r.rterm.windows": "C:\\Users\\<>\\miniconda3\\envs\\r443\\Scripts\\radian.exe"
}
  • OS: Windows
  • VSCode Version: 1.100.3
  • R Version: 4.4.3
  • vscode-R version: 2.8.6

bk1n avatar Jun 05 '25 13:06 bk1n

If it helps, I use the VS Code R extensions since years in combination with conda installed R environments on both linux x86_64 and macos arm64. However, the last working R version in that regard is 4.3.3. Even with that version, it is best to launch VS Code from the command line with the conda environment already activated. It seems the R languageserver does not pick up the configured "r.rpath.linux" or "r.rpath.mac".

With R 4.4.3, the language server starts without errors, but the R Help window never opens if help is requested and the R workspace tools just hang.

Here is my working R 4.3.3 setup:

.vscode/settings.json

{
    "r.rpath.linux": "/home/conda/envs/<conda env name>/bin/r-r.sh",
    "r.rterm.linux": "/home/conda/envs/<conda env name>/bin/r-radian.sh",
    "r.rpath.mac": "/Users/conda/envs/<conda env name>/bin/r-r.sh",
    "r.rterm.mac": "/Users/conda/envs/<conda env name>/bin/r-radian.sh"
}

These shell wrappers are created with:

conda activate <conda env name>
tee $CONDA_PREFIX/bin/r-radian.sh >/dev/null <<-'EOT'
#!/bin/bash
source /home/conda/etc/profile.d/conda.sh
conda activate <conda env name>
/home/conda/envs/<conda env name>/bin/radian
EOT
chmod +x $CONDA_PREFIX/bin/r-radian.sh

tee $CONDA_PREFIX/bin/r-r.sh >/dev/null <<-'EOT'
#!/bin/bash
source /home/conda/etc/profile.d/conda.sh
conda activate <conda env name>
/home/conda/envs/<conda env name>/bin/R --no-save "\$@"
EOT
chmod +x $CONDA_PREFIX/bin/r-r.sh

Please note radian is best installed with pip. The Python version I use is 3.12.

mbiomeai avatar Jul 10 '25 13:07 mbiomeai