R is a useful tool for scientific computing because
We’ll be using RStudio: a free, open source R integrated development environment (IDE). It provides a built in editor, works on all platforms (including on servers) and provides many advantages such as integration with version control and project management.
Something to keep in mind as we use R is just one tool to conduct analyses efficiently and to do so in a way that is reproducible (by you and others). Thus, the goal here is not to teach you how to use R, but to use this software to teach you how to think about and analyze data.
Basic layout
When you first open RStudio, you will be greeted by three panels:
Once you open files, such as R scripts, an editor panel will also open in the top left.
You can type on the “command line” in the console window. However, just as with bash, you will want to save your code in a script. Saving code is easy in R Studio.
File - New Project
New Directory
and Empty Project
To keep track of the commands you are running in a script:
File - New File - R Script
Now you have a fourth window to keep track of commands.
It is possible to add functions to R by obtaining a package written by someone else. As of this writing, there are over 7,000 packages available on CRAN (the comprehensive R archive network). R and RStudio have functionality for managing packages:
installed.packages()
install.packages("packagename")
, where packagename
is the package name, in quotes.update.packages()
remove.packages("packagename")
library(packagename)
Install the following packages: ggplot2
, plyr
, gapminder
, curl
if you have not done so already.