{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"---\n",
"output:\n",
" html_document: default\n",
" pdf_document: default\n",
"---\n",
"\n",
"# Task 3: How to integrate Git with R Studio\n",
"\n",
"This task is designed for students and researchers who want to implement a system of version control within a standard R-based workflow. This can be applied to a range of software development, data analysis and project management tasks. Your future research self will thank your for the convenience.\n",
"\n",
"Don't forget you can join in the discussions over at our open [**Slack channel**](https://openmooc-ers-slackin.herokuapp.com/). Please do introduce yourself at #module5opensource, and tell us a bit about who you are, your background, and how you ended up here!\n",
"\n",
"Estimated time to complete: 30 minutes\n",
"\n",
"Estimate time saving once complete: Virtually infinite\n",
"\n",
"**NOTE** A video guide version of this task is now available on [YouTube](https://www.youtube.com/watch?v=Q-6jfjSAspA).\n",
"\n",
"## Table of contents\n",
"\n",
"* [Getting started](#Getting_started)\n",
" * [Git](#Git)\n",
" * [R Studio](#Rstudio)\n",
"* [Step one: Download all the things](#one)\n",
"* [Step two: Configure Git inside RStudio](#two)\n",
"* [Step three: Why did I just do that?](#three)\n",
"* [Step four: The perfect marriage between Git and R](#four)\n",
"* [Step five: Getting content with content](#five)\n",
"* [Step six: A brave commitment](#six)\n",
"* [Step seven: PUSH!](#seven)\n",
"\n",
"\n",
"## Getting started \n",
"\n",
"Congratulations on making it this far! If you're reading this, you've survived pull requests, web-hooks, and can probably even tell us know what the F in FOSS stands for (*not* Frustration...) Hopefully, you have overcome any scepticism or reluctance towards the benefits of GitHub and Open Source Software, and are ready to take the next step.\n",
"\n",
"Before starting this Task, please make sure you have already completed [Task 1](https://github.com/OpenScienceMOOC/Module-5-Open-Research-Software-and-Open-Source/blob/master/content_development/Task_1.md) and [Task 2](https://github.com/OpenScienceMOOC/Module-5-Open-Research-Software-and-Open-Source/blob/master/content_development/Task_2.md), so that you are more familiar with GitHub and some standard Open Source practices.\n",
"\n",
"This task will teach you how to integrate the version control software, Git, with the popular coding environment, RStudio. And yes, it is Git as in gif or God, not Jit as in the wrong way of pronouncing things.\n",
"\n",
"If you are one of those researchers who thinks that having code spread across multiple hard-drives that are waiting to break, Dropbox, Google Drive, or any other non-specialist software, this task is just for you. If you have ever experienced the mind-numbing process of having multiple 'final' versions of a paper bouncing between different co-authors, this is also for you.\n",
"\n",
"All of us are guilty of these sorts of things once in a while, but there are ways to do it that are better for you, future you, and those who might benefit from your work.\n",
"\n",
"
\n",
"\n",
"### Getting Git \n",
"\n",
"So, what is Git, and how is it different to GitHub? Git is a version control system, which enables you to save and track time-stamped copies of your work throughout the development process. It also works with non-code items too, like this MOOC, the majority of which was written in markdown in RStudio, and integrated with a Git/GitHub workflow.\n",
"\n",
"This is important, as all research goes through changes and sometimes we want to know what those things were. Did you delete some text that you now think is important? Version control will save that for you. Did your code work perfectly in the past, but is now buggy beyond belief? Version control. It's a great way to avoid that chaotic state where you have multiple copies of the same file, but without a stupid and annoying file naming convention. `FINAL_Revised_2.2_supervisor_edits_ver1.7_scream.txt` will be a thing of the past.\n",
"\n",
"GitHub is the platform that allows you to seamlessly share code from your workspace (e.g., laptop) to be hosted in an online space. So, sort of like the public interface to GitHub. The advantages of Git/GitHub are:\n",
"\n",
"1. You get to keep copies of all your work through time;\n",
"2. You can compare work through different copies through time, which helps to spot bugs or errors;\n",
"3. Other people can collaborate openly with your work;\n",
"4. You have both a local and an online copy of your work that remain in sync;\n",
"5. It is fully transparent as to who made a contribution, why they made it, and when; and\n",
"6. You can have multiple people working on the same project at once in parallel.\n",
"\n",
"While this was primarily designed for source code, it should be instantly obvious how this becomes a powerful tool for virtually all research workflows.\n",
"\n",
"
\n",
"\n",
"### RStudio \n",
"\n",
"RStudio is a popular coding environment for researchers who use the statistical programming language, R. It comes with a text editor, so you don't have to install another and switch between. It also includes a graphical user interface (GUI) to Git and GitHub, which we will be using here.\n",
"\n",
"Isn't it nice when brilliant Open Source tools integrate seamlessly like that. This should help to make your daily use of Git much simpler.\n",
"\n",
"If at any point you need to install new packages for R, simply use the following command:\n",
"\n",
"`install.packages(\"PACKAGE NAME\", dependencies = TRUE)`\n",
"\n",
"Replacing `PACKAGE NAME` with the, er, package name. Some examples you can play with that might come in useful include `knitr`, `devtools` or `ggplot2`.\n",
"\n",
"
\n",
"\n",
"## Step one: Download all the things \n",
"\n",
"1. You should already have a GitHub account by now if you have followed the previous tasks. If not, [sign up here](https://github.com/). Free unlimited repositories for all!\n",
"2. Download and install the latest version of [R](https://www.r-project.org/). Also available for [Mac](https://cloud.r-project.org/) and [Linux](https://cloud.r-project.org/bin/linux/).\n",
"3. Download and install the latest version of [Rstudio](https://www.rstudio.com/products/rstudio/#Desktop). Oh, hey, looks it Open Source! Swish.\n",
"4. Download and install the latest version of [Git](https://gitforwindows.org/). **Make sure to Select “Use Git from the Windows Command Prompt” during installation.**\n",
"\n",
"> **Pro-tip**: To update all of your R packages in one, simply execute the following code `update.packages(ask = FALSE, checkBuilt = TRUE)`\n",
"\n",
"For now, just choose all the usual default options for each install. Depending on which Operating System (e.g., Mac, Windows, Linux), this might be different for each of you. For now, and for the rest of this task, we're going to stick with doing things the easy-ish Windows way (but also provide some instructions for using the command line).\n",
"\n",
"For Linux or Debian users, simply use the following command to install Git:\n",
"\n",
"`sudo apt-get install git-core`\n",
"\n",
"For Mac users, [this link](http://git-scm.com/download/mac), or purchase a new laptop with a different operating system.\n",
"\n",
"If you want, you can also download the [local version of GitHub](https://desktop.github.com/) and use it through the simple GUI. It's available on Windows and Mac and Linux, and can make your life a little easier, especially if you want to use a different platform to RStudio.\n",
"\n",
"> **Pro-tip:** You see when installing Git it says 'Use Git Bash as shell for Git projects?' This is the place where you can use the command-line to access Git from outside of RStudio. It's a powerful beast. Try the following two commands to get started:\n",
"\n",
"`git config --global user.name 'YOUR USERNAME'`\n",
"
\n",
"`git config --global user.email 'YOUR EMAIL'`\n",
"
\n",
"\n",
"## Step two: Configure Git inside RStudio \n",
"\n",
"Right, that's the easy bit done. Next, go into RStudio, and in the tabs at the top go to Go to **Tools > Global Options > Git/SVN**. SVN is just another version control system like Git, and we don't need to worry about that here.\n",
"\n",
"In the place where it says *Git executable*, add the pathway here to the git.exe file that you just downloaded in the previous step. Make sure the box here that says **Enable version control interface for RStudio projects** is ticked. This now has tied version control to future projects in RStudio, to provide a really powerful additional dimension to collaborative or solo work.\n",
"\n",
"
\n", " \n", "
\n", "\n", "The Global Options window inside RStudio
\n", "\n", "\n", " \n", "
\n", "\n", "Inside GitHub where you will want to enter the key you just generated in RStudio
\n", "\n", "\n", " \n", "
\n", "\n", "Screenshot of what this module looks in markdown, during development. Meta.
\n", "\n", "