Using R in Visual Studio Code with conda environment

Viewed 2450
2 Answers

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/

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:

  • open 'vscode'
  • install the extension and configure it as suggested using the conda paths for both R and, if you have it installed, radian
  • close 'vscode'
  • open a terminal
  • activate your conda environment
  • start 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.

Related