vscode-R: I can't attach any R session to VS Code when using a remote server via SSH and it can't find the binary either.
I am using a conda virtual environment for a research project conducted at a remote server which I access via SSH.
I use the [Remote SSH] (https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-ssh) extension to connect to the host and then I need to edit R files there. The code below shows that both R and radian are correctly set, I believe:
(r_conda) [rgr6291@klc0201 bin]$ conda env list
# conda environments:
#
fomc /home/rgr6291/.conda/envs/fomc
r_conda * /home/rgr6291/.conda/envs/r_conda
rfe_paper /home/rgr6291/.conda/envs/rfe_paper
base /software/python-anaconda3/2019.10
(r_conda) [rgr6291@klc0201 bin]$ which R
~/.conda/envs/r_conda/bin/R
(r_conda) [rgr6291@klc0201 bin]$ which radian
~/.conda/envs/r_conda/bin/radian
In the settings for the R extension, I have set these binaries as the RPath and the Rterm:
{
"r.rpath.linux": "~/.conda/envs/r_conda/bin/R",
"r.rterm.linux": "~/.conda/envs/r_conda/bin/radian"
}
However, I get errors like this one when I try to attach an R session:
Cannot find R client at ~/.conda/envs/r_conda/bin/radian. Please check r.rterm setting.
And also it complains that it can’t find the jsonlite package although it has been installed:
Failed to get list of R functions. Make sure that
jsonliteis installed and r.rpath.linux points to a valid R executable.
What am I missing here?
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 4
- Comments: 21 (6 by maintainers)
Hi !
My environment is the same as raulguarini (OP): VsCode + R extension + SSH remote shell (Linux) + R only available through a Conda environment on the remote. I haven’t tried to use radiant. After struggling a bit I just found how to use the Conda env properly, so I’m sharing it here.
In my case, the Conda environment also contains R packages (tidyverse etc) and an ODBC driver that I need to use from R. In order to use syntax highlighting from VsCode, I installed
r-languageserverandr-jsonlitein my Conda environment.Three options: the first one is a bit easier but not complete enough for me. I went for Option 3.
I hope this can help someone else! If so, maybe document it somewhere? Pierre
Option 1
In the settings for the R extension, set RPath and the Rterm: (NB: I avoided “~” in the paths, not sure if expansion would work or not)
Result: R is available, tidyverse also OK but not the ODBC driver is not accessible from R.
Option 2
As suggested in #623, you can try to set
"r.alwaysUseActiveTerminal": truein the VsCode settings. Then manually start a terminal, Conda-activate and start R. After that you should be able to submit R commands (e.g. with Ctrl+Enter). I find it less comfortable and didn’t try it.Option 3
Write a little shell script which first activates Conda and then starts R. I wrote it in
/path/to/myproject/R-conda.shand made it executable (chmod +x R-conda.sh)Then I pointed VsCode-R to this script in the settings:
Result: R is available, tidyverse and the ODBC driver are accessible from R.
Option 2 worked for me after conda installing
r-languageserverandr-jsonlite- thanks so much for this post!! I like option 2 for constructing new code, but option 3 with command line args is probably better for debugging.