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-languageserveron 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. Create new project folder.

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 "print("Hello!")" 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() command results, and R version in footer highlighted.

 

 

For Additional Assistance

 

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