Reputation: 1443
I would like to use the R environment I installed with conda inside Visual Studio Code (on Macos). First I installed R with conda. But how do I use/activate the environment in Visual Studio Code? In the settings I can't find the equivalent to "Python: Select Interpreter" or "python.venvPath" Thanks!
Upvotes: 14
Views: 9097
Reputation: 1
A workaround which works for me:
# Check if the R executable exists in the activated environment
R_PATH=$(which R)
if [ -z "$R_PATH" ]; then
echo "R is not found in the activated conda environment: $1"
exit 1
fi
# Start R using the path from the activated environment
exec "$R_PATH" # Execute R
"r.rterm.linux": "/path/to/start_R.sh"
Python: Select Interpreter
to select your chosen conda environment.Now when opening an R terminal it should use the correct conda environment.
Upvotes: 0
Reputation: 3
Detailed configuration steps similar to @Andrea's idea could be found at this post.
If you want to attach VSCode-R to your current R session (e.g., opened in a Conda environment), an additional step to modify the .Rprofile
is needed.
Upvotes: 0
Reputation: 355
It has been 2 years since this entry and the extension still doesn't support conda
environments.
For my configuration (I've R
installed in a conda
environment), I found a pretty painless work around:
conda
paths for both R
and, if you have it installed, radian
vscode
from your terminal using code
After this, everything seems to be up and running correctly. You can start an R terminal using the command palette and, as you run your code, you should be able to see all the information about the environment and namespaces as well as your plots.
Upvotes: 8
Reputation: 57686
R support in VSCode is handled by a 3rd party extension. The most popular one is R by Yuki Ueda and there is also R Tools by Mikhail Arkhipov
For both of these, you can change the R interpreter to use in the settings.
However, there is no built-in support for Anaconda, mostly because it isn't that popular or necessary in the R community. Most people use the standard R installation instead and most help resources are written for that type of installation: https://cloud.r-project.org/bin/macosx/
Upvotes: 7