Installing R

  1. Go to the R:/Stats/R/ folder 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. You may be asked if you would like to create a personal library - select Yes and accept the default folder location

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

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

  8. If you get an error message saying that the install location isn’t writable, follow the steps below

    1. Go to C:/Users and open your profile folder

    2. Right-click on the “My Documents” shortcut

    3. Select Properties \(\rightarrow\) Security Tab \(\rightarrow\) Advanced

    4. Select Owner Tab\(\rightarrow\) edit \(\rightarrow\) make yourself the owner \(\rightarrow\) OK

    5. After taking ownership you will likely get a notice, click OK and then close out of the ‘My Documents Properties’ window

    6. Once again, right-click on the “My Documents” shortcut

    7. Select Properties \(\rightarrow\) Security Tab \(\rightarrow\) Advanced

    8. Select Everyone in the top window and then click Change Permissions \(\rightarrow\) check the Allow box for Full control then click OK and then close out of the ‘My Documents Properties’ window

    9. Return to the R console and once more, type install.packages("data.table")

    10. The data.table package (and its dependencies) should begin installing

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

  10. 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'))

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

Installing RStudio

  1. Return to the R:/Stats/R/ folder and download latest version of RStudio

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

  3. 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. Rtools is available in the J:\R folder

  2. To connect Rtools follow the steps below to edit the system path

    1. Perform a system search for ‘Environment Variables’

    2. Choose Edit Environment Variables For Your Account

    3. Find the variable Path \(\rightarrow\) click Edit \(\rightarrow\) add J:\R\Rtools\bin;J:\R\Rtools\gcc-4.6.3\bin

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

    5. Run devtools::find_rtools()

      • If this returns TRUE you’re all set

      • If this returns FALSE check the directory in which Rtools is located

Installing \(\LaTeX\)

  1. \(\LaTeX\) should already be installed on most AFIT machines follow these steps to check

    1. Open C:/Program Files(x86)

    2. Look for a folder MiKTeX 2.9

    3. If this folder is there \(\LaTeX\) is already installed on your machine (go to step 3)

    4. If you do not see this folder, follow the steps below to get \(\LaTeX\) installed

  2. If \(\LaTeX\) isn’t installed, you can install it from the R:/Latex/MikTeX folder

  1. Double click “Complete_Install 2.9.3959” (NOT 2.9.5105)

  2. Follow the prompts for a complete installation

  3. For page size: Letter

  4. For Packages-on-the-fly: Yes

  1. Once MiKTeX installs, open RStudio and click to create a new file

    1. Choose R Markdown to create a new Rmarkdown file *.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, browse to the R:/Latex/packages folder

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

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 four lines

    2. git config --global http.proxy http://username@proxyedu1.afit.edu:8080

    3. git config --global https.proxy https://username@proxyedu1.afit.edu:8080

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

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

    6. 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