Integrating GitHub Copilot with RStudio and VScode

Coding, RStudio, R, VScode, GitHub
Author
Affiliation

Stephen Lang & Dan Padfield

University of Exeter

Published

July 19, 2024

Modified

November 27, 2024

Outline

GitHub Copilot is a useful way to integrate LLM’s into our coding process. These tools should be used with some care, so see our ‘Using GitHub Copilot and other LLM’s in our Coding workflows’ presentation for more information and guidance.

This walkthrough will provide the necessary steps to add Copilot to RStudio and VScode/Positron.

Prerequisites

To access Copilot for free, you will need to request GitHub education benefits using the following steps:

  1. Sign up for a GitHub account (ideally using your university account)
  2. From your new GitHub account, apply for free GitHub Education benefits (i.e., upload photo of your Unicard)
  3. Once GitHub Education email to say your application is approved, head to https://github.com/settings/copilot and click the Start free trial button
  4. The next screen will have a green button to Get access to GitHub Copilot
  5. Finally, you just have to check policies (for additional details see here) and click Save and complete setup
  6. You’re now ready to set up GitHub copilot!

Setting up Copilot in RStudio

  1. To set up the GitHub Copilot for RStudio, we navigate to Tools > Global Options > Copilot (see image below)
  2. From the Copilot tab, check the Enable Copilot box and hit Apply
  3. You should then see a You are not currently signed in message below the checkbox. Click the Sign in button.
  4. Copy the 8-digit code, click the link, select Continue and paste the code
  5. Copilot should show as activated (if not click the Activate button in Copilot options)
  6. Copilot will now provide suggestions for code as you type (you can see status in bottom right of the code window)

Setting up Copilot for Visual Studio Code

  1. On VS Code we just have to install the GitHub Copilot extension
  2. Once installed, we open the Copilot extension and use it to sign into our GitHub account
  3. Copilot will now give you suggestions as you type, and you can also use the additional Copilot chat feature (messages icon on left of window) to open a dialogue

General Copilot usage and pointers

Now we have Copilot ready to provide suggestions for our code in our chosen software!

  • To approve Copilot suggestions that appear, press Tab
  • To give Copilot guidance on code suggestions, provide #code comments that describe steps required
  • Make sure to check both the generated code itself and sense-check outputs to ensure that it is doing what is expected
  • The Copilot chat extension (installed automatically alongside Copilot) can be used for a broader range of tasks – see examples here

Additional Resources

Acknowledgements

We did not create this content alone! Inspiration, tips, and resources have been borrowed from multiple sources.