Chapter 1 Install R and RStudio
Install R, a free software environment for statistical computing and graphics from CRAN, the Comprehensive R Archive Network. It is highly recommended to install a precompiled binary distribution for your operating system (OS) – by using the links up at the top of the CRAN page linked above.
Install RStudio’s IDE (integrated development environment), a powerful user interface for R. Get the Open Source Edition of RStudio Desktop.
- The official releases are available here.
- RStudio comes with a text editor, so there is no immediate need to install a separate stand-alone editor.
- RStudio can interface with Git(Hub). However, you must do all the Git(Hub) set up described elsewhere before you can take advantage of this. This is not required for the course, but it is recommended if you want to foster the reproducibility of your data analysis workflow with R.
If you have a pre-existing installation of R and/or RStudio, it is highly recommended that you reinstall both and get the last available versions. It can be considerably harder to run old software than new.
If you upgrade R, you will need to update any packages you have installed. The command below should get you started, though you may need to specify more arguments if, e.g., you have been using a non-default library for your packages.
Using update.packages()
will only look for updates on CRAN. So if you use a package that lives only on GitHub or if you want a development version from GitHub, you will need to update manually, e.g., via devtools::install_github()
.
1.1 Testing testing
Do whatever is appropriate for your OS to launch RStudio. You should get a window similar to the screenshot you see here, but yours will be more boring because you haven’t written any code or made any figures yet!
Put your cursor in the pane labeled Console, which is where you interact with the live R process. Create a simple object with code like
x <- 2 * 4
(followed by enter or return). Then inspect thex
object by typingx
followed by enter or return. You should see the value 8 print to screen. If so, you have successfully installed R and RStudio.
1.2 Add-on packages
R is an extensible system and many people share useful code they have developed as a package via CRAN and GitHub. To install a package from CRAN, for example the dplyr package for data manipulation, here is one way to do it in the R console (there are others).
By including dependencies = TRUE
, we are being explicit and extra-careful to install any additional packages the target package, dplyr in the example above, needs to have around.
You could use the above method to install the following packages, all of which we will use:
- tidyr, package webpage
- ggplot2, package webpage
1.3 Further resources
The above will get your basic setup ready but here are some links if you are interested in getting more information: