Few days ago, a colleague asked me how to upload some R code on GitHub in order to make it accessible to everyone. Due to the lockdown, I could not just go into his office and show him on his computer. So I sent him several screenshots showing, step by step, how to do so.
Right before I deleted the screenshots I’d just taken, I thought that perhaps they would be useful for other persons, so I wrote this article.
Note 1: The screenshots have been taken on MacOS and I have not tested it on Windows. Do not hesitate to let me know in the comments whether it is similar or not on other operating systems.
Note 2: There must be other ways to do it, but the method shown below is (in my opinion) easy and works well.
In order to follow this guide and upload your R code on GitHub, you will need at least:
For this guide, I use a R script created to plot the evolution of the hospital admissions due to COVID-19 in Belgium. See the repository on GitHub in case you want to see the final result before proceeding further.
You often hear
“A picture is worth a thousand words”
So here is without further ado how to upload your R script on GitHub in images:
Be careful that if you choose to make it public, it will be visible to everyone. If you do not want to share the code, but still want it to be uploaded on GitHub, choose the private option.
Initializing the repo with a README file is not mandatory, but I strongly recommend it so you will be able to add information for this repo.
(See how to install R and RStudio if you are unfamiliar with it.)
You can see the path to the folder in step 6 c, under “Local Path”.
In step 10, make sure that the current repository (see top left) is the repo you are currently working on.
Your R code is now available online via the new repository on your GitHub profile. If you need to share it, you can simply share the URL of the repo.
If you need to edit your code:
After your script is saved, do not forget to commit the changes and push the commit (see step 10 above).
In case you need to see an old version of your code, you can see all commits by clicking on the commits tab accessible via the repo on github.com:
Thanks for reading. I hope this article helped you to create a GitHub repository, and upload your R scripts so that it is available to anyone.
As always, if you have a question or a suggestion related to the topic covered in this article, please add it as a comment so other readers can benefit from the discussion.