The Data Scientist’s Toolbox: Linking Github and R Studio
By: Kurt F.
Tags: Git And Rstudio, Data Scientist Git, Data Science Toolbox, Data Science, Data Scientist Rstudio

In this post, we will learn how to connect RStudio and Github, which are very important in joint application and projecting for data science.

RStudio is a free, open source IDE (integrated development environment) for R. Of course you need to install R before installing RStudio.

Why Use RStudio?

First of all, this is not the main subject of this post. However, to briefly touch on RStudio:

Its interface is organized so that the user can clearly view graphs, data tables, R code, and output all at the same time

It also offers an Import-Wizard-like feature that allows users to import CSV, Excel, SAS (*.sas7bdat), SPSS (*.sav), and Stata (*.dta) files into R without having to write the code

R Studio remembers which files are open and restores the working environment as if it were never exit

There is only one place to look at so it’s much easier to share your work with others since everything related to a project is in the same place.

As you know, version control is a very important tool for explaining who, when and why changes in software were made.

Thanks to Version Control:

Version control allows multiple people to work on the same file, and helps to combine all versions and all edits of the file into a single combined file

Git is a free and open source version control system. A local copy of your work and revisions, which you can clarify later offline.

When you return to the internet service, you can fully synchronize your copy of your work, make new edits, and track changes in the main repository online

For this, our first goal will be to install git and connect it to R Studio.

Step-1: In RStudio go to Tools, then Global Options, then Git / SVN

Image by author

Step-2: To link RStudio to GitHub in the same RStudio options window, click “Create RSA Key” and click “Close” when done.

Image by author

Step-3: Again in the same window, click “View public key” and copy the string of numbers and letters. And close this window.

Image by author

Now, whenever you make a change in RStudio, you have created a key so that GitHub can display it.

Step-4: Go to github.com and login and go to your account settings. Go to SSH and GPG keys and click “New SSH key”. Paste it into the public key copied from RStudio. Switch box and give it a title related to RStudio.

Image by author

Step-5: Confirm the addition of the key with your GitHub password.

Image by author

Step-6: Now we can create a repository in GitHub and connect to RStudio. To do this, go to GitHub and a new repository by going to Your Profile, Repositories and New. Name your new test pool and give a brief description. Click “Create a new Repository”, copy the URL of your new repository.

Image by author

Step-7: In RStudio go to File, New Project, choose “Version Control”, choose “Git: Clone a project from a Git repository” as your version control software. Paste the repository URL before, choose where you want the project to be stored. When done, click “Create Project”.

Image by author

Step-8: Create a new R script by going to File, New File, find the R Script and copy and paste the following code: print (“This file was created in RStudio”) and then paste it on a new line, print (“And now it lives on GitHub “). Save the file. When you do this, the default location for the file is the new project directory you created earlier.

Image by author

Step-9: Click the checkbox under “Staged” to prepare your file. Then click “Diff” and the panel will open showing the differences in “Stage” files from previous versions. On the right tab, type a message of your choice in the “Commit” message box and click “Save”.

Image by author

And your “Commit” is ready to “Push”

Image by author

Step-10: The next step is to transfer your changes to your online repository. Submit your changes to the GitHub repository.

Image by author

And happy ending! Go to your GitHub repository and see the transaction has been saved. You have successfully submitted your first transaction to GitHub from RStudio