Using Github Copilot

Using Github Copilot

This document accompanies the DIYtranscriptomics course and is intended to provide basic guidance in how use the AI-powered utility, Github Copilot, to accelerate your work in R and RStudio

Github Copilot is a generative AI tool referred to as a ‘pair programmer’. This means that it works with you to create code. Under the hood, Copilot is using the OpenAI Codex model that is trained on billions of lines of code from virtually every coding language. This makes it an incredibly powerful tool to assist you in your day-to-day coding tasks. Normally, Copilot requires a monthly or annual paid subscription, but the tool is free to students. Unfortunately, it’s not obvious how to access this tool, so I’ve provided some instructions below for you to follow.

Get the Github Student Development Pack

Follow the steps below to gain access to the Github Student Development Pack, which includes many useful tools and perks, including Github Copilot.

  1. Visit the Github student developer main page
  2. Sign Up for the student developer pack
  3. Select “Get Student Benefit”
  4. Sign-in to your GitHub account. If you don’t have a Github account, register for a free one now.
  5. Add your school email. This process usually needs some authentication, because a code will be sent to your school email for verification.
  6. Enter the name of your school
  7. Answer the questions on how you plan to use GitHub.
  8. On some occasions, more proof might be required. So you might need to upload either of school identity card or any other form of proof of study validity.
  9. Submit the application. In many cases the approval occurs within seconds to minutes

Connect Copilot to your Github account

Now you're ready to connect Copilot to your Github account. To do this, go to the Copilot website and log in.

Then, go to your user icon (upper right) and choose ‘Settings’ from the drop down menu

image

Once on the settings page, click on Co-pilot in the left hand menu and confirm that you have successfully linked co-pilot to your github account

image

Turn on Copilot in RStudio

Now that you have Copilot linked to your github account, you need to link RStudio to your Github account and turn on Copilot in RStudio.

Open RStudio and from the main menu choose Tools → Global Options

From the pop-up window that opens choose Copilot from the left-hand menu

image

Start coding using Copilot

With Copilot now turned on, you will see ‘suggested’ code and comments listed in light grey ‘ghosted’ and italicized text. If you don’t like the suggestion you see, simply keep typing and the suggestion will disappear. However, if you like the suggestion, hit ‘tab’ on your keyboard the suggestion becomes part of your script!

Tips and suggestions

  • Rethink the purpose of code comments. Comments now become prompts for the AI algorithm.
  • The ‘Introduction’ code chunk should provide a high level description of what it is you hope to accomplish with this script. This gives Copilot some necessary scope and helps inform that kind of suggestions you’ll be receiving
  • if you don’t like the Copilot suggestion, try modifying your prompt to be more specific (this is called prompt engineering)
  • If you’re not a native english speaker, that’s OK. Copilot is multilingual!
  • Copilot, like any AI tools right now, will get things wrong. For example, Copilot might suggest using a variable or function that doesn’t even exist. Check the suggestions. Even wrong suggestions can still be useful.
  • Like a plot you already made? Use copilot to iterate on this. For example, “make the last plot interactive”
  • Copilot uses a technique called neighboring tabs that allows the AI pair programmer to contextualize your code by processing all of the files open in your IDE instead of just the single file you’re working on
  • If you modify some suggested code, Copilot will learn from this. For example, if the suggested code creates an object called ‘file’ and you change to ‘file_01’, then the next time Copilot suggests creating an object, it will suggest ‘file_02’.