Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
hermidalc opened this issue Jun 14, 2022 · 7 comments

Comments

@hermidalc
Copy link

hermidalc commented Jun 14, 2022

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 hermidalc changed the title How to automatically context switch bettween different conda environment R and radians depending on currently opened file? Setting R, radian, and libraries at the project folder level (from conda environment) Jun 14, 2022
@elsherbini
Copy link

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

@hermidalc
Copy link
Author

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 hermidalc changed the title Setting R, radian, and libraries at the project folder level (from conda environment) R and radian paths from per project folder and project conda environment (i.e. make vscode-R design like vscode-python) Jun 15, 2022
@hermidalc hermidalc changed the title R and radian paths from per project folder and project conda environment (i.e. make vscode-R design like vscode-python) R and radian paths from per project folder/conda environment (i.e. make vscode-R design like vscode-python) Jun 15, 2022
@hermidalc
Copy link
Author

hermidalc commented Jun 15, 2022

Repeating what I wrote in #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 hermidalc changed the title R and radian paths from per project folder/conda environment (i.e. make vscode-R design like vscode-python) R and radian paths per project folder/conda environment (i.e. make vscode-R design like vscode-python) Jun 15, 2022
@gwd666
Copy link

gwd666 commented Jul 1, 2022

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

@ElianHugh ElianHugh mentioned this issue Jul 5, 2022
11 tasks
@github-actions
Copy link

github-actions bot commented Jul 2, 2023

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

@github-actions github-actions bot added the stale label Jul 2, 2023
@EasyPiPi
Copy link

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

@github-actions github-actions bot removed the stale label Jul 15, 2023
@torbjorn
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants