How-To: Using VS Code as IDE in Conda Environment for Python and R Development - Windows

Question

How do I use VS Code as the integrated development environment (IDE) in a Conda environment for Python and R development in Windows?

 

Answer

Note:  Miniconda should already be installed, see How-To: Install Miniconda Without Administrator Privileges in Windows.

 

Note:  VS Code should already be installed from Software Center, see How-To: Software Center: Install Software for Windows.

 

1. Using Anaconda Prompt, create Conda environment for use with R, enter "conda create -n <env-name> -c conda-forge r-base r-essentials r-languageserver" on the command line.

Example environment: r_env_t4

How-To: RStudio: Create Conda Environment for Using RStudio

 

2. Activate new conda environment, enter "conda activate <env-name>" on the command line.

Example environment: r_env_t4

How-To: Using Anaconda - Activate a Virtual Conda Environment via Command Line Interface

 

3. Launch VS Code from the prompt, enter "code" on the command line.

 

4. In VS Code, install Python extension by Microsoft.

a. Select Extensions icon.

b. Enter "python" in Extensions: Marketplace search box.

c. Select "Install" for the Python language support... by Microsoft.

VS Code left extensions list pane with python extension highlighted.

 

5. Install R extension by REditorSupport.

a. Enter "R" in Extensions: Marketplace search box.

b. Select "Install" for the R Extension for Visual Studio Code by REditorSupport.

VS Code left extensions list pane with R extension highlighted.

 

6. Extensions installed.

VS Code left extensions list pane with extensions installed.

 

7.  Create new project folder.

a. Select Explorer icon.

b. Select the New Folder icon.

c. Enter new project folder name.

VS Code explorer pane with new project folder
 

8. Create a new R file in project directory

VS Code explorer pane with new file. 

 

9. Add command print("Hello!") to new file.

10. Run file to verify R integration.

VS Code center file pane with quotation mark print left parentheses quotation mark Hello! closing parentheses quotation mark command.

 

11. Verify operation and integration.

a. Confirm output "Hello!".

b. Confirm R version is displayed.

c. Enter R.home() and confirm result path is within active Conda environment.

Example: /Users/<username>/miniconda3/envs/r_t4_env/lib/R

VS Code terminal window with print command output, R.home open parenthses close parentheses command results, and R version in footer highlighted.

 

 

For Additional Assistance

 

https://code.visualstudio.com/docs/languages/r

For additional assistance or questions about this article, please contact itrss@missouri.edu

Print Article

Related Articles (2)

Using VS Code as Integrated Development Environment (IDE) in Conda Environment for Python and R Development - Mac
Index of Advanced Topics for Conda, Python, and R