Introduction to R

We will be using the statistical software environment R throughout the program’s lectures and labs. R is an open-source programming language specifically designed for statistical computing and graphics. In addition to its vast library of built-in functions for working with data, the extensibility of R allows statisticians and data scientists to continuously develop new packages for its community to use. This has led R to be adopted by academic researchers and organizations across various industries such as sports.

Please follow the steps below for set-up prior to beginning the program on June 1st.

Installing R

  • Open an internet browser and go to www.r-project.org.
  • Click the download R link in the middle of the page under “Getting Started.”
  • Select a CRAN location (a mirror site, preferably a location close to you) and click the corresponding link.

For Mac Users:

  • Click on the “Download R for (Mac) OS X” link at the top of the page.
  • Click on the file containing the latest version of R (which is now 4.0.0)
  • Save the .pkg file, double-click it to open, and follow the installation instructions.

For Windows Users:

  • Click on the “Download R for Windows” link at the top of the page.
  • Click on the “install R for the first time” link at the top of the page.
  • Click “Download R 4.0.0 for Windows” and save the executable file somewhere on your computer. Run the .exe file and follow the installation instructions.

Installing RStudio

Although though can use R without it, you will need to install RStudio for CMSACamp. RStudio is by far the most popular integrated development environment (IDE) for R. Basically, it makes your life with R much easier and we will be using it throughout the program. To Install RStudio:

Installing tidyverse

The tidyverse is a popular suite of R packages we will be using throughout the summer, including the popular data visualization package ggplot2. After installing R and RStudio, open RStudio and proceed to enter the following command in the Console pane on the left-hand side:

install.packages("tidyverse")

Then make sure the tidyverse suite of packages are successfully installed by running:

library(tidyverse)

If you encounter any issues or errors in any of these installation steps above, including the tidyverse, please contact the instructors.

R Primers on RStudio Cloud

In addition to following the steps above for installing R and RStudio on your computer, we want you to make a free RStudio Cloud account at https://rstudio.cloud/. This is a free, browser-based version of R and RStudio that also provides access to a growing number of R tutorials / primers relevant to CMSACamp.

After you create a RStudio Cloud account, click on the navigation menu by “Your Workspace”. Then click on “Primers” to bring up a menu of tutorials. Prior to June 1st, please complete the following (listed in order of importance):

Feel free to explore the other primers listed, specifically for “Iterate” and “Tidy Your Data”. We will be covering data visualization extensively in the first two weeks, so you do not worry about working through the data visualization primers.

After completing the above primers available on the RStudio Cloud, try replicating the some type of R programming basics in your own local version of R and RStudio installed on your computer. RStudio Cloud is a great practical alternative to use in case we are unable to resolve errors with regards to installation on your own personal computer (an unlikely scenario). We strongly encourage you to use an installed version of R and RStudio throughout the program, due to RStudio Cloud data limitations that are important for your research projects throughout the summer.

LS0tCnRpdGxlOiAiUiBCYWNrZ3JvdW5kIE1hdGVyaWFsIgpvdXRwdXQ6IGh0bWxfZG9jdW1lbnQKLS0tCgojIyBJbnRyb2R1Y3Rpb24gdG8gYFJgIAoKV2Ugd2lsbCBiZSB1c2luZyB0aGUgc3RhdGlzdGljYWwgc29mdHdhcmUgZW52aXJvbm1lbnQgYFJgIHRocm91Z2hvdXQgdGhlIHByb2dyYW0ncyBsZWN0dXJlcyBhbmQgbGFicy4gYFJgIGlzIGFuIG9wZW4tc291cmNlIHByb2dyYW1taW5nIGxhbmd1YWdlIHNwZWNpZmljYWxseSBkZXNpZ25lZCBmb3Igc3RhdGlzdGljYWwgY29tcHV0aW5nIGFuZCBncmFwaGljcy4gSW4gYWRkaXRpb24gdG8gaXRzIHZhc3QgbGlicmFyeSBvZiBidWlsdC1pbiBmdW5jdGlvbnMgZm9yIHdvcmtpbmcgd2l0aCBkYXRhLCB0aGUgZXh0ZW5zaWJpbGl0eSBvZiBgUmAgYWxsb3dzIHN0YXRpc3RpY2lhbnMgYW5kIGRhdGEgc2NpZW50aXN0cyB0byBjb250aW51b3VzbHkgZGV2ZWxvcCBuZXcgcGFja2FnZXMgZm9yIGl0cyBjb21tdW5pdHkgdG8gdXNlLiBUaGlzIGhhcyBsZWQgYFJgIHRvIGJlIGFkb3B0ZWQgYnkgYWNhZGVtaWMgcmVzZWFyY2hlcnMgYW5kIG9yZ2FuaXphdGlvbnMgYWNyb3NzIHZhcmlvdXMgaW5kdXN0cmllcyBzdWNoIGFzIHNwb3J0cy4KCl9fUGxlYXNlIGZvbGxvdyB0aGUgc3RlcHMgYmVsb3cgZm9yIHNldC11cCBwcmlvciB0byBiZWdpbm5pbmcgdGhlIHByb2dyYW0gb24gS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