COMET
  • Get Started
    • Quickstart Guide
    • Install and Use COMET
    • Get Started
  • Learn By Skill Level
    • Getting Started
    • Beginner
    • Intermediate - Econometrics
    • Intermediate - Geospatial
    • Advanced

    • Browse All
  • Learn By Class
    • Making Sense of Economic Data (ECON 226/227)
    • Econometrics I (ECON 325)
    • Econometrics II (ECON 326)
    • Statistics in Geography (GEOG 374)
  • Learn to Research
    • Learn How to Do a Project
  • Teach With COMET
    • Learn how to teach with Jupyter and COMET
    • Using COMET in the Classroom
    • See COMET presentations
  • Contribute
    • Install for Development
    • Write Self Tests
  • Launch COMET
    • Launch on JupyterOpen (with Data)
    • Launch on JupyterOpen (lite)
    • Launch on Syzygy
    • Launch on Colab
    • Launch Locally

    • Project Datasets
    • Github Repository
  • |
  • About
    • COMET Team
    • Copyright Information

On this page

  • Prerequisites
  • Why use an IDE?
  • Using COMET with VSCode
  • 1. Installing R
  • 2. Installing a R package Compiler
  • 3. Installing MiniConda
  • 4. Setting up our environment
  • 5. Configuring the IRKernel and Installing REditorSupport
  • 6. Opening the COMET modules
  • Report an issue

Using VSCode

Last Updated

14 January 2025

Prerequisites

  1. Have installed VSCode on your device.

Why use an IDE?

An IDE, also known as a integrated development environment, is a software application that streamlines software development. Using an IDE such as VSCode is often better than locally hosting a jupyter notebook because it allows us to avoid using CLIs, offers code assistance just as syntax highlighting, and has a built-in highly customizable and extensible environment with a vast library of extensions.

Using COMET with VSCode

1. Installing R

The first thing we’ll need to do is install R onto our computer.

  • Windows
  • MacOS
  1. Head to cran.r-project.org for windows and press Download R-4.4.0 for Windows
  2. Select Okay > Next and select your destination location.
  3. Select the components Main files, 64-bit files and Message translations. Then, press next.
  4. Select the toggle No (acccept defaults) and press next.
  5. Select both save version number in registry and associate R with .RData files.
  6. Once the installation is complete, press Finish.
  1. Head to cran.r-project.org for macOSx and select the release (on the left-hand side) suited for your device type.
  2. Open the installer and select continue > continue > continue > agree > install.

2. Installing a R package Compiler

We’ll need to install a package compiler in order to compile R packages from source.

  • Windows
  • MacOS

RTools is a program that allows us to compile R packages.

Rtools can be installed with link.

In the Rtools installer, press Next > Next (ensuring that both check boxes are ticked) > Install.

For Mac, you’ll need to install Xcode Command Line Tools instead.

  1. Open the Mac terminal. To do so, click on the spotlight icon in the menu bar and search for “terminal.”
  2. Install Homebrew: Homebrew is a package manager for MacOS which we will use to install Xcode. In the Mac terminal, paste:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

This might prompt you to enter your user password, which is the password that you use to sign into your device (Note that for privacy reasons you won’t be able to see the characters that you type). Once you’ve entered your password, press enter. This may take a while to run.

  1. You should get an output similar to this:

Notice the warning. To fix this, we’ll need to add our installation to the system path. In the terminal, run:

(echo; echo 'eval "$(/opt/homebrew/bin/brew shellenv)"') >> ~/.zprofile

followed by:

eval "$(/opt/homebrew/bin/brew shellenv)"

which will add the required path to the installation.

  1. Verify installations: to check that Xtools is installed, run $ brew doctor in the termial. This should display the output “Your system is ready to brew.”

3. Installing MiniConda

Additionally, we’ll need to do is install miniconda, a python distribution that allows us to simplify package installations. Head to anaconda.com and follow the instructions below, depending on your operating system.

  • Windows
  • MacOS
  1. Scroll to Latest Miniconda installer links and select Miniconda3 Windows 64-bit.
  2. Open the installer, and select next > I Agree > Just Me (recommended).
  3. Select your destination folder of choice and press next.
  4. Select the following options:
  • Add Miniconda3 to my PATH environment variable
  • Register Miniconda3 as my default Python 3.12
  • Clear the package cache upon completion
  1. Lastly, press install.
  1. Scroll to Latest Miniconda installer links and select the version compatible with your device.
  2. Open the installer and follow the instructions.

4. Setting up our environment

Before we download the comet modules, we’ll need to set up our environment and install required packages.

  1. In your computer file system, search for Anaconda Prompt (miniconda3) in your files and open it as an administrator. This should open up a terminal.

  2. In the terminal, enter the following line code:

conda create -n comet jupyterlab r-essentials git r-tidyverse r-car r-stargazer r-estimatr

The first part of this command will create a new python environment called “comet”. An envrionment is an isolated space on your computer where you can work on a given project without the risk of breaking other projects. Essentially, this acts as a safety layer to protect our computer.

The second part of this command will add the required r packages for the COMET modules to the environment.

Lastly, to enable the environment, run conda activate comet_env.

5. Configuring the IRKernel and Installing REditorSupport

We’ll now set up the kernel that will allow us to code in the R programming language in VSCode.

  1. Open the copy of R 4.4.0 that we installed earlier.

  2. In the terminal, paste the following lines of code one at a time:

install.packages('IRkernel') This will prompt you to select a CRAN mirror. Select the one closest to you (if you are at UBC, that would be Canada (MB)).

IRkernel::installspec()

  1. We’ll now need to install the VSCode REditorSupport extension, which will allow us to interact with the R terminal from within VScode.
  1. Open R 4.4.0 and paste install.packages("languageserver"). Make sure to select the CRAN mirror closest to you.
  2. In VSCode, open the extensions page. You can do so by pressing Ctrl+Shift+X on Windows, or Cmd+Shift+X on MacOS. Alternatively, you can find the extensions panel on the left-hand side of your screen.

  1. In the extensions search, type r and select the first option.

  2. Press install. You should now be able to access the R terminal directly from the VSCode console. You may need to close and reopen VSCode.

  1. You can access the R terminal directly though VSCode by right-clicking the arrow next to the + in the terminal and selecting R interactive.

6. Opening the COMET modules

Lastly, we need to actually be able to open and work on the COMET modules in VSCode.

  1. Open comet.arts.ubc.ca and, in the top right corner, select Launch Comet > Launch Locally. This will download a .zip file to your computer.
  2. Open the file in file explorer and extract the zip folder to your prefered destination.
  3. In VSCode, select File > Open Folder and select the COMET folder that you just unzipped. This will open the comet modules on your computer!

  • Creative Commons License. See details.
 
  • Report an issue
  • The COMET Project and the UBC Vancouver School of Economics are located on the traditional, ancestral and unceded territory of the xʷməθkʷəy̓əm (Musqueam) and Sḵwx̱wú7mesh (Squamish) peoples.