Table of Contents
Please sign-up for GitHub Copilot before the workshop.
If you are applying for free Copilot access as a student or teacher, the application is easy, however it can take a few days to process (GitHub warns it can even take up to two weeks, though we have not experienced this).
In order to follow along in the workshop, you must have access to Copilot. If you are a student or teacher, you can get free access to Copilot, but you must first be verified (see 1.2 Sign-up for Copilot). Otherwise, you will have to pay for a subscription, which starts at $10/month (plans available here). If this is your first time using Copilot, you can also start a 30 day free trial. If you would like to run the workshop on your own computer (recommended) we also request that you install R and VS Code before the workshop (see 2. Setting up VS Code).
To use GitHub Copilot you will need to create a GitHub account.
Steps:
- Go to https://github.com/
- Click Sign up
- Sign up with your institutional email, if you have one. You can also add your institutional email later if you want to use another email (instructions here)
- Follow the prompts to create your personal account. Pick your username carefully, you will likely not want to change it. Some recommendations (inspired by https://happygitwithr.com/github-acct):
- Use part of your real name so it is easier for people to know who you are
- Try and keep it short, you may have to type it a lot
- Keep everything lowercase. If you really want to separate words, use a hyphen (-) or an underscore (_)
GitHub Copilot is free for verified students and teachers. Otherwise, Copilot is $10/month or $100/year for their most basic individual account. You can get a free 30-day trial if it is your first time signing up.
If you are not a student or teacher, you can sign-up for a paid version of Copilot here:
https://github.com/features/copilot/plans
To get free Copilot for teachers and students you need to apply for benefits here (don’t worry, it’s easy!):
https://education.github.com/discount_requests/application
You will need to fill out a short application which will ask you some basic information about yourself and your institution. Your institutional email must be associated with your GitHub account (instructions for adding an email to your Github account can be found here). You will need to provide proof of your affiliation. This proof must have your name, a current date, and the name of your institution on it. If your application is rejected, it is most likely because your proof of affiliation was missing one of these three things (but, you can always apply again with new proof!). For example, some UC Berkeley student IDs do not have a date on them, so they will not be accepted. You may also have to follow some additional steps to verify your GitHub account, make sure to check your email for instructions. We have also heard of a bug that results in .png files not being accepted while .jpeg files are.
If you are a UC Berkeley student, the most straightforward way to get proof is to download a certificate of enrollment verification by going to CalCentral > My Academics > Enrollment Verification (under Academic Records) > View or Print Enrollment via Self Service > Obtain an enrollment certificate. This will give you a PDF enrollment certificate which you can screenshot and submit for proof of affiliation (you need to use a screenshot because the application does not accept PDFs).
If you have a problem submitting your application please submit a D-Lab consulting request here with the subject line “GitHub Co-pilot workshop: applying for student developer pack”: https://dlab.berkeley.edu/consulting/submit-consulting-request
Note: when you are creating a GitHub Co-pilot account you will be prompted to select whether GitHub can allow suggestions matching public code. You may want to select Blocked
if you are worried about licensing and intellectual property, but for most of us it is better to select Allowed
so we get access to more sources for our code.
We will be using GitHub Copilot in Visual Studio Code (VS Code), a free code editor that allows you to work with a wide variety of languages including R, Python, and many others. If you have worked with RStudio before, you will find many parts of VS Code familiar.
Visual studio has extensive documentation describing how to setup and use VS Code, which can be found here:
https://code.visualstudio.com/docs
We summarize the steps described in their documentation below.
First, install VS Code onto your computer: https://code.visualstudio.com/download
Detailed setup instructions can be found here:
- Mac - https://code.visualstudio.com/docs/setup/mac
- Windows - https://code.visualstudio.com/docs/setup/windows
- Linux - https://code.visualstudio.com/docs/setup/linux
Check out this video tutorial for a brief overview of VS Code: https://code.visualstudio.com/learn/get-started/basics
The instructions below are mostly copied from the original VS Code documentation which can be found here: https://code.visualstudio.com/docs/languages/r
Steps:
-
If you don’t have R on your computer already, Install R (>= 3.4.0) for your platform. For Windows users, it is recommended to check “Save version number in registry” during installation so that the R extension can find your R installation automatically. If you have not done this you may need to add the location of your R to your PATH manually (see FAQ 3.1 I am using windows and my VS Code can’t find R!).
-
Install the “languageserver” and “httpgd” R packages in R
- Open a window in R (you can do this by either opening the R or RStudio app on your computer or using any other way you like to run R). Sometimes, the R app seems to “disappear” in windows. If you can’t find your R app on your windows computer, click the windows icon on the bottom left of your screen, click “all apps”, scroll down until you find the R folder, and click the R version you want to run.
- Install the “languageserver” package by running:
install.packages(“languageserver”)
- In order to view our plots interactively we also want to install the “httpgd” package in R which we can do by running:
install.packages(“httpgd”)
-
Install the R extension for VS Code. This “extension” is what allows R to access your installed R and use it to run your R code. VS Code has many extensions that allow you to do everything from running R to connecting to remote servers.
- Open VS Code
- Click on the Extensions icon in the toolbar on the left side
- Look up “R” and click the “Install” button to install R
-
Done! Now you can run R code by either opening or creating an R file in VS Code (to create a file click File > New File… and selecting R document or R markdown from the files). Note that VS Code uses lowercase .r and .rmd by default, but it will also accept .R and .Rmd files. To run R code, just click “Ctrl + Enter” and you will see your code run in a new R Interactive terminal window (analogous to the RStudio console)
To use GitHub Copilot in VS Code we will make use of the GitHub Copilot extension.
The instructions below are mostly copied from the original VS Code documentation which can be found here: https://code.visualstudio.com/docs/copilot/setup
More information about using Copilot in VS Code can be found here:
https://code.visualstudio.com/docs/copilot/overview
Steps:
-
Make sure you have an active GitHub Copilot subscription (see 1. GitHub Copilot). VS Code will prompt you to sign-in to your GitHub account which has access to Copilot.
-
Install the GitHub Copilot extension
- Open VS Code
- Click on the Extensions icon in the toolbar on the left side
-
- Look up “GitHub Copilot” and click the “Install” button to install Copilot. This will also automatically install “GitHub Copilot Chat”
- Done! You will notice that a new chat bubble icon has been added to your left toolbar. Click on this button to start Copilot chat or click “Ctrl + Shift +I” to start Quick Chat and “Ctrl + I” to start in-line chat (see workshop materials or VS Code documentation for more information: https://code.visualstudio.com/docs/copilot/getting-started)
If you are getting an error in VS Code that is something like “Cannot find R” this means that VS Code does not know where R is on your computer. To tell your computer (and VS Code) where your R is, we must add the location (known as the “path”) to your R installation to something called the “PATH”. The “PATH” is a list of folders that your computer looks at to find programs you want to run, like R. To add R to your PATH:
- First, find the location (path) to your R installation:
- Open File Explorer
- Navigate to the directory where R is installed. By default, it is usually in C:\Program Files\R\R-x.x.x\bin (where x.x.x is the version number).
- Copy the path to the bin folder by right clicking on the bin folder and selecting “Copy as path” or “Ctrl+Shift+C”). It might look something like C:\Program Files\R\R-4.4.0\bin.
- Add the R path to your system PATH:
- Option 1:
- Press “Win + X” keys on the keyboard and select System from the list. Inside the System window, click on Advanced system settings
- Inside the advanced system settings, click on the Environment Variables button at the bottom.
- Option 2:
- Click on the Search bar in the lower right hand of your screen
- Look up “Edit the system environmental variables” and click the suggestion
- Click on the Environment Variables button at the bottom.
- Find the System variables section, and scroll down to find the Path variable.
- Select it and click on Edit.
- In the Edit Environment Variable window, click on New and paste the path you copied earlier (for example: C:\Program Files\R\R-4.4.0bin).
- Click OK to close all windows.
- Option 1:
- Verify the R Path Addition:
- Open Command Prompt. You can do this by pressing “Win + R”, typing “cmd”, and hitting Enter.
- Type R --version and press Enter. If everything is set up correctly, you should see the version information for R displayed.
- Make sure to restart VS Code (close all windows) in order for this change to take effect in VS Code.
No, VS Code will reference your existing R installation, so whatever you have downloaded there will be in VS Code.
When you open a new VS Code window you will see on the Welcome screen suggestions to open a file or a folder. If you open a folder (recommended), when you start running R you will be inside that folder (run getwd() to confirm this). If you open a file, you will be wherever your default working directory is – which is usually your user profile directory (e.g., C:\Users\<YourUsername> on windows).
If you don't see a "Run Chunk" option in your R markdown file, you may need to edit your settings to recognize the file type. To do this:
- Type
Ctrl + Shift + P
orCmd + Shift + P
to open the command palette - in the search bar look up and click
Preferences: Open User Settings (JSON)
- In this file, look for the section that says
"files.associations": {
and edit it so it looks like this:
"files.associations": {
"*.rmd": "rmarkdown",
"*.Rmd": "rmarkdown"
}