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

R and radian paths per project folder/conda environment (i.e. make vscode-R design like vscode-python)

Open hermidalc opened this issue 3 years ago • 7 comments

I'm new to VSCode (just moved from Atom because it's being retired), and I'm trying to understand how to set up the R extension to work seamlessly with conda environments at the project folder level. Each of the project folders in my workspace is associated with its own conda environment, with it's own R and radian builds/versions and libraries. But when I go to my settings, the R extension settings disappear when you look at the folder level vs workspace level.

How can I set up the R extension to automatically switch to the appropriate project folder conda environment R, radian, and libraries for the project file I currently have open within that specific project folder? VSCode can do this with python and I've set that up, so every time I open a code file from a specific project it just context switches to the appropriate conda environment, python, and libraries.

I want to do the same with R. But when I open an R file in a project folder, in the status bar it shows R: (not attached). When I try to attach it with an open terminal the auto-pasted .vsc.attach() doesn't work. Cannot figure out how to fix this.

hermidalc avatar Jun 14 '22 13:06 hermidalc

This is going to be the blind leading the blind, so if someone else can chime in that'd be great.

But what happens when you open the command prompt (F1) and run the command R: Create R terminal ?

What settings do you have for the vscode-R extension for Rterm path?

One way forward would be to make a wrapper script and point the Rterm path to that, something like:

~/activate_local_conda_and_start_R.sh

#!/bin/bash

cd $(dirname $0)

# First we need to init conda bc ~/.bashrc is not executed when starting non-interactive shells. 
# Assuming PATH was already set by parent shell, and reusing script in profile.d/ if possible...
__conda_init_file=$(dirname $(which conda))/../etc/profile.d/conda.sh
if [ -f "$__conda_init_file" ]; then
    source "$__conda_init_file"
else
    eval "$(conda shell.bash hook 2> /dev/null)"
fi    

# Now we can activate
conda deactivate && conda activate ./

# And start R, passing through all command-line arguments
R --no-save --no-restore

elsherbini avatar Jun 15 '22 18:06 elsherbini

But what happens when you open the command prompt (F1) and run the command R: Create R terminal ?

Cannot find R client at radian. Please check r.rterm setting.

My r.rterm is the default radian without a path, as it should be. vscode-R should be smart like the python VSCode design and I should be able to select an interpreter per project folder from an auto populated list of conda environments and python binary paths that VSCode figured out. This is how code dev should be because each project has it's own dependencies/versions/builds. The same for R code files and projects with R code.

Why didn't the vscode-R devs just use the exact same design as was done for the python side? That design just makes sense and works beautifully, and I can have different files in different projects open simultaneously and it will automatically switch to the appropriate binaries and env based on the file in focus.

hermidalc avatar Jun 15 '22 18:06 hermidalc

Repeating what I wrote in https://github.com/REditorSupport/vscode-R/issues/696 which is pretty much asking for the same thing and what isn't mentioned there is many R users will not have a single R install and will use something like mamba/conda where, per project/github repo, one will have a conda environment with it's own R, radian, and libraries each with their own versions/builds required by that particular project.

The feature request for me would be to make vscode-R work exactly the same as vscode-python. I should be able to hit Ctrl + Shift + P -> R: Select Interpreter and an auto-populated drop-down list of all the R binaries avail on my computer will be shown and I should be able to select this binary (and by extension the conda env) per project folder (or workspace level).

Then in the lower right-hand status bar should show in place of the Python (Extension) status info it should have the R (Extension) status info with e.g. 4.1.3 ('myenv': conda)

Also this entire thing with R: (not attached) should be seamless and automatically attach the R/radian from above.

hermidalc avatar Jun 15 '22 18:06 hermidalc

My r.rterm is the default radian without a path, as it should be.

I kinda like to squeeze the --r-binary=/path/to/bin/R.exe (notice not going further down architecture paths like x64 or i386 here) in there in the "additional parameters" and then making the architecture a parameter there as well with providing --arch x64 and --arch i386

gwd666 avatar Jul 01 '22 19:07 gwd666

This issue is stale because it has been open for 365 days with no activity.

github-actions[bot] avatar Jul 02 '23 02:07 github-actions[bot]

Met the same problem as the original question. Try to attach R within a conda env but without any luck.

EasyPiPi avatar Jul 14 '23 18:07 EasyPiPi

If I understand correctly, now being another year later, I still have to manually go to vscode settings and change the path in r.rterm to whatever path radian has for a given host and/or project?

.. And nobody cares that this is horrendous?

torbjorn avatar Oct 15 '23 13:10 torbjorn