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

Vscode R LSP cannot work with a R installed in conda env

Open littlemingone opened this issue 1 year ago • 5 comments

Hello guys. I am using Vscode to work on R language for some data analyses. The r-base was installed in a conda environment. And I found that the R terminal cannot work with barely configuration of r.path.xx and r.term.xx pointing to the R.exe in conda env. But with the Python Addon, I can activate a conda env before I start a R terminal.

The R interperter itself can work prefectly after I Python: Select Interperter to configure which conda env to be use. But I found that the R Language Server seem to work independently and doesn’t influenced by the Python: Select Interperter. As the result, the R LSP launched without activating correct conda env and the R launched failed due to missing dll files. How can I launch the R LSP in a conda env?

By the way, I found that an r-base installed by conda cannot work without activating its conda env but a R installed by the CRAN R installer can be use at anywhere. It works even copy the whole directory to another PC. What makes this diffrence and can I make the conda r-base work in such a standalone mode?

littlemingone avatar Sep 03 '24 09:09 littlemingone

It requires the dynamic (dll/so) of libblas, liblapack etc. shipped with conda in the system PATH, or can be found in some way.

ShuguangSun avatar Sep 04 '24 05:09 ShuguangSun

It requires the dynamic (dll/so) of libblas, liblapack etc. shipped with conda in the system PATH, or can be found in some way.

OK, it works, thank you!

But I still find it a bit wired that in order to use a conda environment I need to write its path in the PATH instead of activating it somehow.

littlemingone avatar Sep 04 '24 06:09 littlemingone

could you give some details? I add the dynamic (dll/so) of libblas, liblapack etc to my system PATH,but it couldn't work.This is my setting { "workbench.colorTheme": "Solarized Light", "python.defaultInterpreterPath": "C:\Users\34681\AppData\Local\Programs\Python\Python39\python.exe", "fittencode.languagePreference.displayPreference": "zh-cn", "fittencode.languagePreference.commentPreference": "zh-cn", "extensions.experimental.affinity": { "asvetliakov.vscode-neovim": 1 }, "workbench.editor.enablePreview": false, "cursor.cpp.enablePartialAccepts": true, "files.associations": { ".rmd": "markdown" }, "r.workspaceViewer.removeHiddenItems": true, "r.workspaceViewer.showObjectSize": true, "r.plot.defaults.colorTheme": "vscode", "r.plot.useHttpgd": true, "r.rpath.windows": "D:\anaconda\envs\r-4.4.2\lib\R", "editor.largeFileOptimizations": false, "r.terminalPath": "C:\Program Files\R\R-4.4.2\bin\R.exe", "r.interpreterPath": "C:\Program Files\R\R-4.4.2\bin\R.exe", "[json]": { "editor.defaultFormatter": "esbenp.prettier-vscode" }, "workbench.editorAssociations": { ".json": "jsonGridViewer.json" }, "r.rterm.option": [ "--no-save", "--no-restore" ], "background.customImages": [], "r.rterm.windows": "D:\anaconda\envs\r-4.4.2\lib\R\bin\R.exe" "terminal.integrated.env.windows": { "R_HOME": "D:\anaconda\envs\r-4.4.2\lib\R" } } And this is my Path

Image And this is my error.

It indicates a missing DLL file or dependency issue when trying to run R.exe in VSCode

laohanyin avatar Apr 10 '25 08:04 laohanyin

"r.rpath.windows": "D:\anaconda\envs\r-4.4.2\lib\R", "editor.largeFileOptimizations": false, "r.terminalPath": "C:\Program Files\R\R-4.4.2\bin\R.exe", "r.interpreterPath": "C:\Program Files\R\R-4.4.2\bin\R.exe",

I think here should be part of the problem. Your r.rpath.windows is be the detail path to R.exe, for example E:\Program\miniforge3\envs\R-4.4.1\lib\R\bin\R.exe. And I'm not quite sure if r.terminalPath and r.interpreterPath are valid configuration items, but they point to your R-4.4.2 installed by CRAN r-installer but not the one in conda env. Maybe you want to use r.rterm.windows?

According to my experience,missing DLL errors are caused by vscode tried to launch a R term in conda env without acitive the conda env first. You may get the same error when you tried to directly launch the R.exe in D:\anaconda\envs\r-4.4.2\lib\R\bin\R.exe when you are at base env.

You need to configure your conda path first. And pres shift+ctrl+P to open the vscode command search ,then find Python: Select Interpreter to select the correct conda env with r-base inside. Then the env should be activated and you R.exe can be launched.

Image

Here is my full settings.json

settings.json

{ "editor.suggest.shareSuggestSelections": true, "r.rterm.option": [ "--no-site-file", "--r-binary=E:\Program\miniforge3\envs\R-4.4.1\Scripts\R.exe" ], "r.alwaysUseActiveTerminal": true, "terminal.integrated.env.windows": { }, "r.rpath.windows": "E:\Program\miniforge3\envs\R-4.4.1\lib\R\bin\R.exe", "python.condaPath": "E:\Program\miniforge3\Scripts\conda.exe", "terminal.integrated.defaultProfile.windows": "PowerShell", "python.createEnvironment.contentButton": "show", "terminal.integrated.profiles.windows": { "PowerShell": { "source": "PowerShell", "icon": "terminal-powershell" }, "Command Prompt": { "path": [ "${env:windir}\Sysnative\cmd.exe", "${env:windir}\System32\cmd.exe" ], "args": [], "icon": "terminal-cmd" }, "Git Bash": { "source": "Git Bash" } }, "files.autoGuessEncoding": true, "r.plot.useHttpgd": true, "editor.tabSize": 2, "editor.fontLigatures": true, "editor.fontFamily": "'Cascadia Code', 'Cascadia Code PL', 'Cascadia Code NF', Consolas, monospace", "settingsSync.ignoredSettings": [ "r.rpath.windows", "r.rterm.option", "r.rterm.windows" ], "editor.fontSize": 15, "editor.wrappingIndent": "indent", "editor.minimap.enabled": false, "terminal.explorerKind": "external", "[markdown]": { "editor.defaultFormatter": "esbenp.prettier-vscode" }, "markdown-image.sftp.path": "/assets/img", "markdown-image.base.altFormat": "", "markdown-image.base.fileNameFormat": "${mdname}/${hash}", "markdown-image.local.path": "/assets/img", "markdown-image.local.referencePath": "/assets/img/${mdname}/", "git.autofetch": true, "terminal.integrated.enableMultiLinePasteWarning": false, "Key Promoter.ignoredCommands": [ "type", "deleteLeft", "editor.action.triggerSuggest", "acceptSelectedSuggestion", "selectNextSuggestion", "editor.action.clipboardCopyAction", "workbench.action.terminal.scrollToBottom", "editor.action.clipboardPasteAction", "editor.action.webvieweditor.findNext" ], "editor.suggest.showStatusBar": true, "debug.showInStatusBar": "always", "terminal.integrated.enableVisualBell": true, "r.rterm.windows": "E:\Program\miniforge3\envs\R-4.4.1\Scripts\radian.exe", "r.lsp.debug": true, "[r]": { "editor.wordSeparators": "`~!@#$%^&()-=+[{]}\|;:'",<>/", "editor.defaultFormatter": "REditorSupport.r" }, "explorer.copyRelativePathSeparator": "/", "remote.SSH.remotePlatform": { "uprobiotics.cn": "windows" }, "workbench.editorAssociations": { "{git,gitlens,git-graph}:/**/.{md,csv,svg}": "default", "{git,gitlens}:/**/*.{md,csv,svg}": "default" }, "Key Promoter.suggestKeybindingCreation": false, "diffEditor.hideUnchangedRegions.enabled": true, "editor.largeFileOptimizations": false, "vs-browser.autoCompleteUrl": "https://", "editor.defaultFormatter": "esbenp.prettier-vscode", "chat.commandCenter.enabled": false

}

littlemingone avatar Apr 10 '25 09:04 littlemingone

I also have this issue - more details in #1617

bk1n avatar Jul 03 '25 14:07 bk1n