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

  • 1. Installing R
  • 2. Installing RStudio
  • 3. Installing package compilers
  • 4. Downloading and opening the COMET notebooks
    • 4.1. Downloading the COMET notebooks
  • 4.2. Importing the COMET notebooks into RStudio
    • 4.3. Changing your working directory in the files tab.
  • 5. Activating the COMET environment
  • Report an issue

Using RStudio

Last Updated

14 January 2025

This page explains how to set up RStudio in order to access and use the COMET notebooks.

Note

If you are using RStudio, you will want to ensure that you use the .Rmd or .qmd (R Markdown or Quarto) versions of the notebooks, not the .ipynb versions. Currently, RStudio does not natively support the Python notebook format.

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 RStudio

We’ll now install RStudio, our IDE of choice.

  • Windows
  • MacOS
  1. Head to RStudio and press Download RStudio Desktop for windows.
  2. Open the RStudio setup and press Next > Next > Install.
  1. RStudio, scroll down to “OS”, and select the Mac installer.
  2. Open the Rstudio setup and install.

3. Installing package compilers

We’ll need to install a package compiler to activate the renv.lock, a package bundle made specifically for the COMET notebooks.

  • Windows
  • MacOS

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

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.”

4. Downloading and opening the COMET notebooks

4.1. Downloading the COMET notebooks

  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 preferred destination.

4.2. Importing the COMET notebooks into RStudio

We can now import the COMET notebooks into RStudio. When we say “import”, what we really mean is setting the working directory. The working directory is the location in your computer where you are working in. Unlike VSCode and other high-level IDEs, setting our working directory is done manually by specifiying our location using the R console.

  1. Locate the downloaded COMET notebooks and copy the absolute file path by right-clicking on the folder and pressing copy as path. If you are on a Mac, hold the option key and select Copy (file name) as Pathname.
  2. Locate the current working directory in RStudio by entering getwd() in the R console (bottom left of the screen).

The output should look something like this on windows, but won’t necessarily give the same file path.
  1. We’ll now set our working directory to the COMET folder. To do so, enter the following command into the console:

setwd("C:/your/file/path/goes/here")

Where “C:/your/file/path/goes/here” is the absolute file path you copied earlier, with the backshashes (\) set to forward slashes (/). For example, the file path (on windows) C:\users\i_love_econ will be changed to C:/users/i_love_econ.

Warning

RStudio requires file paths to have a forward slash instead of a back slash. If you don’t adjust the absolute file path accordingly, you won’t be able to set/change your working directory.

To check that you’ve got the right working directory, run getwd() again.

4.3. Changing your working directory in the files tab.

On the right-hand bottom side of Rstudio there is a display that shows your files. If you’d like to change it to your current working directory, press the small button ... button called “go to directory”. This will allow you to pick the COMET modules folder from your file system and navigate it from within R.

5. Activating the COMET environment

We’re now ready to activate the COMET environment in RStudio.

  1. In the R console, enter the following line of code: install.packages("renv"). This will install the renv package, which will allow RStudio to read the custom environment file for the notebooks.

  2. In the R console, run renv::restore(). You should get a message that reads: “It looks like you’ve called renv::restore() in a project that hasn’t been activated yet. How would you like to proceed?”. Press 1. This should restart R. If it doesn’t, run renv::activate().

  3. To check that everything is installed properly, run renv::status(). This command will give you a the list of packages in your environment (Note that this might take some time to run).

  • 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.