Installing R

  1. Go to https://cloud.r-project.org/ and download latest version of R

  2. During the installation process, accept all of the defaults

  3. Once the install is complete, open R - admittedly it’s not very exciting to look at, RStudio will help with that

  4. At the command prompt type .libPaths()

    1. This function returns the directories where R can store your downloaded packages

    2. As you’re installing R for the first time, there may be only one directory listed now - as you use R the number of directories is likely to increase

    3. The order of the directories indicates the order R will use in trying to store the package

    4. A custom library may be specified by creating an environment variable called R_LIBS and assigning it the path of the desired folder

    5. If you don’t know how to set environment variables don’t worry about this right now

  5. Now type names(installed.packages()[,1])

    • This returns a list of the packages that installs with R

    • These packages should be stored in the first directory returned by .libPaths()

Installing R Packages

  1. The real power of R is experienced by using AND creating packages

  2. R packages can be downloaded and used like apps on your smartphone

  3. Packages allow researchers to share their work with the world, very quickly

  4. Packages allow users to use the latest methods, almost immediately after they are developed

  5. In many cases there’s an app a package for that!

  6. There are also several ‘stores’ or repositories from which packages can be installed

    1. The Comprehensive R Archive Network (CRAN) - the official repository for R packages

    2. GitHub - many packages are stored here prior to being accepted for publication to the CRAN

    3. Bioconductor - a repository of bioinformatics-related R packages

    4. The Microsoft R Archive Network (MRAN)

  7. Ok, let’s install a package to make sure everything is working

    1. Run install.packages('data.table') to install the data.table package from the CRAN

    2. As this is your first package, you will likely be asked to choose a ‘CRAN mirror’ - select 0 - Cloud

    3. You may then be asked if you would like to create a personal library - select Yes and accept the default folder location

    4. If the package (and it’s dependencies) downloaded you’re all set to continue

    5. If the package failed to download, skip ahead to 2) Installing RStudio and try to install the data.table package again once RStudio is installed

  8. In addition to the data.table package there are several packages every R user needs

  9. To install these packages paste the following lines into R

    1. install.packages(c('installr','devtools','rmarkdown'))

    2. install.packages(c('DT','knitcitations','RefManageR'))

    3. install.packages(c('shiny','RJSONIO','xtable'))

  10. If these packages (and their dependencies) install - you’re all set!

Installing RStudio

  1. In the previous step you attempted to install the installr package from the CRAN

  2. You can verify that the package installed by running "installr"%in%installed.packages()

    1. If the returned value is TRUE your all set, skip down to 3)

    2. If the returned value is FALSE run install.packages("installr")

    3. If this attempt also fails to install the package skip down to 4)

  3. With the installr package RStudio may be installed from within R by running installr::install_rstudio()

  4. Without the installr package RStudio can be installed from HERE

  5. Once installed, open RStudio to ensure it’s linked with the your installed version of R

    1. If your R installation is found, RStudio will open - no news is good news

    2. If your R installation is not found, RStudio will fail to open properly

Installing Rtools

  1. With the installr package, Rtools may be installed from within R by running installr::install_rtools()

  2. Without the installr package Rtools can be installed from HERE

  3. After the install completes, run devtools::find_rtools() to ensure R can find Rtools

    1. If this function returns TRUE go on to \(\LaTeX\)

    2. If this function returns FALSE follow the steps below to edit the system path

      • Perform a search for ‘Environment Variables’

      • If you have admin rights, choose Edit the System Environment Variables otherwise choose Edit Environment Variables For Your Account

      • Find the variable Path \(\rightarrow\) click Edit \(\rightarrow\) add c:\Rtools\bin;c:\Rtools\gcc-4.6.3\bin

      • If the Path variable doesn’t exist or isn’t editable click New \(\rightarrow\) create the variable Path \(\rightarrow\) assign the value c:\Rtools\bin;c:\Rtools\gcc-4.6.3\bin

      • Once again, run devtools::find_rtools() if this still returns FALSE check the directory in which Rtools is located

Installing \(\LaTeX\)

  1. With the installr package, MiKTeX may be installed from within R by running installr::install_miktex()

  2. Without the installr package MiKTeX can be installed from HERE

    1. Choose to Install Packages on the Fly

    2. Otherwise accept all the defaults

  3. Once installed, open RStudio and click to create a new file

    1. Choose R Markdown to create a new Rmarkdown file filename.Rmd

    2. In the ‘Document’ dialog choose ‘PDF Document’

    3. Once the demo file opens, click to knit the rmarkdown file into a PDF document

    4. If a pop-up window appears, asking permission to install a \(\LaTeX\) package, check the default location of the package repository and allow the package to install

    5. The first time a document knits into a PDF it can take a minute to install the packages

Create a GitHub Account

  1. Go to GitHub.com and sign up for an account

    1. Choose a username

    2. Add an email address (don’t use your afit.edu address as your primary, you can add it as a secondary address later)

    3. Enter a password

  2. After logging in, search for Auburngrads/test-repo to find the test-repo repository created by Auburngrads

  3. On the test-repo page click to fork a copy of the repo to your account

Install & Configure Git

  1. With the installr package, Git may be installed from within R by running installr::install_git()

  2. Without the installr package Git can be installed from HERE

  3. Once the install completes, close and re-open RStudio

    1. Open the ‘Tools’ menu and select ‘Global Options’

    2. In ‘Global Options’ select ‘Git/SVN’

    3. If the ‘Git Executable’ window is blank click ‘Browse’ and navigate to C:\Program Files\Git\bin\bin.exe click OK

    4. If the path to git.exe is already listed in the ‘Git Executable’ window, Git has been installed correctly

  4. Next, we’ll make sure Git is configured

    1. Search your machine for the ‘Git Bash’ application, open the application and type the following two lines

    2. git config --global user.name your.github.username

    3. git config --global user.email your.github.email

    4. Close Git Bash

  5. Finally, let’s set up the SSH connection between RStudio and GitHub

    1. Open ‘Tools’ \(\rightarrow\) ‘Global Options’ \(\rightarrow\) ‘Git/SVN’

    2. Toward the bottom of the ‘Git/SVN’ dialog click ‘Create RSA Key’

    3. After the RSA Key appears click ‘Close’

    4. Click ‘View Public Key’ and copy the text in the window

    5. Return to your GitHub.com account page and click the drop-down arrow next to your account avatar (upper-right corner) \(\rightarrow\) select ‘Settings’

    6. Under ‘Settings’ select ‘SSH and GPG Keys’

    7. Select ‘New SSH Key’ \(\rightarrow\) choose a name for the key, like personal machine

    8. Paste the public key in the window and select ‘Add SSH Key’

Creating & Linking RProjects

  1. Click and select ‘New Project’

  2. At the menu select ‘Version Control’ and then ‘Git’

  3. Enter the repository url

    1. If you’ve set-up SSH enter the url as git@github.com:your.user.name/test-repo.git

    2. If you have not set up SSH enter the url as https://github.com/your.user.name/test-repo.git

  4. Select ‘OK’ and Git will clone the test-repo to your machine

  5. Once the project opens, edit and commit the changes to the README.md file

    1. Add your initials to the list of initials and save the file

    2. Find the project tabs in the upper-right pane of RStudio

    3. Select the ‘Git’ tab

    4. The README.md file should be listed as a changed file

    5. Click the checkbox next to the filename and then click ‘Commit’

    6. In the Commit dialog, enter a short message in the window detailing the changes you made and click Commit

  6. Now that the changes have been committed they need to be Pushed so that their online counterparts match

    1. Close the Commit dialog and press Push

    2. A window may appear asking for a username and password - ignore this.

    3. After the Push is complete a message will appear indicating that the changes have been syned to the Master branch

  7. Submit a Pull-Request to sync the changes in your version of test-repo to my version of test-repo

    1. Navigate to the test-repo repository page under your account

    2. Select Pull requests \(\rightarrow\) ‘New Pull Request’

    3. Git will perform a Diff to determine which files have been changed

    4. As only the README.md file is changed between the two repos this should be the only file listed.

    5. Select ‘Create Pull Request’

  8. Once the pull request is finished - so is the process to build R/RStudio toolchain for data science