How to upload R code on GitHub in 10 steps.

https://mk0whatcounts5gas29i.kinstacdn.com/wp-content/uploads/2016/02/sharing-is-caring.jpg

Background

Few months ago, I created a GitHub account during a data health hackathon. In this Greek hackathon we were asked to explore and suggest ways to utilize public health Greek data (it also happens that our team won 1st prize, our presentation in Greek can be found here). Then, we had to upload the code in GitHub to make it available to everyone. After uploading the initial code, I quit using the platform for a couple of years.

Recently I came back to GitHub by the need to create a personal website. Then, I tried to upload the R code for a project I was working on in R with Shiny. After I uploaded my code, I invited collaborators to work on it. Apparently GitHub gives you tremendous possibilities to share you code, collaborate with colleagues, gain feedback or provide feedback or fixes to existing repositories.

A repository is the basic place where a project is being uploaded in GitHub.

The following tutorial is based on the way I set GitHub in my main Windows 10 computer, though, I believe it could be interchangeable between other OSs.

A 10-step by step Guide

Requirements

The following two are at least required to move along this guide:

1. a GitHub account
2. an installed GitHub Desktop application in your computer

Steps

As this guide example I will be using the first Rshiny code I uploaded in GitHub for the Shiny implementation of the gamlss.demo package, a package the demonstrates smoothing and distributions of the gamlss family. Of course, you could sneak peek the repository on GitHub if you would like to see the current uploaded code before further following the tutorial.

The result application can be found uploaded in a Virtual machine of Google cloud server that I set earlier.

In 10 steps I am now presenting an easy (but probably not the only) way to start sharing R code in GitHub.

No 1. Visit https://github.com and create an account by setting the following. Validate your account and you are set.

No 2. The main github screen is the following. On the left your future repositories will appear. For now just click on the green right button “New”.

No 3. In this screen fill up the name of the new repository “gamlss_shiny”, choose if the repository will be public or private, then insert a readme file which will act as a description and finally add a license or not.

No 4. The next github screen will be an empty repository with title gamlss_shiny and maximum two files a readme.md and a licence file. The description of the readme.md file appears at the bottom of the repository. Files can be changed directly through this interface. If clicked they all give the chance to edit. New files can also be added via the Add file button. Folders can be created by the same Add file button by clicking Add file and then typing for example folder2/file2.txt you will create a text file named “file2” in the folder named “folder2”

No 5. Open the Github Desktop application on your computer. You will have to be connected with the same GitHub account credentials that you are using in GitHub website. Then, press the Clone repository and the following screen will appear. Find or search for the new repository, then click “Clone”. The first connection is already there!

No 6. You will see a new folder with the two files, as in step No 4.

No 7. In this step, drag and drop your R code files and folders in the new repository folder in the empty repository folder. All changes and additions will be noted in GitHub Desktop. At the lower right part of the application enter a name and optinally a description for the changes. For example in the first upload enter just Initial submit. In later alterations you can be more specific. Then, click on “commit to main”.

No 8. In this step you have to click the “Push origin” button and send the changes to GitHub. If all went well then in the Push Origin tab no arrows or notifications will appear.

No 9. You can check every repository’s history changes if you click on the History tab under Current repository.

No 10. All files are now added in GitHub repository. You can share the code by clicking the green Code button and sharing the url. In our example case the following url: https://github.com/kpatera/gamlss_shiny.git. To add code through the desktop application make sure you have first pulled all online code to avoid code conflicts.

The Online Rshiny application that corresponds to the above repository can be found here.

If you have any suggestions on the guide above send me a message or comment below.

Picture: https://www.whatcounts.com/sharing-is-caring/

This entry was posted in STArT and tagged , , , , , , . Bookmark the permalink.

Leave a comment