R Programming - Getting Started
So you want to learn R programming. Good for you. This page will hopefully walk you through getting into R.
Contents
Reading
There are numerous good tutorials, getting started, and so forth for R. Reading through just about any of them is good for you. Here are a few you can try, but feel free to pick your own as well.
- R Tutorial on TutorialsPoint - mostly a high level overview, many parts suitable for people with very limited programming experience.
- R Manuals - from the official R website, these tend to be more in depth and aimed at an audience who already has some programming experience.
- R Getting Started - summary / intro by Jeff Kinne
Software Setup
R is free to use and has numerous free packages as well. We recommend using the Rstudio IDE since it is the most popular and has some very nice features.
Install on Your Computer
- Download and install the latest version of R from https://cloud.r-project.org
- Download and install Rstudio deskttop (the free version) from https://www.rstudio.com/products/rstudio/download/
Use on ISU CS Systems
To use R on the ISU CS systems, you can either use Rstudio when you are in one of the labs or run R from the terminal when you are logged in remotely. To run Rstudio on one of the CS lab computers, simply run the rstudio command (either from a terminal, or via the graphical menu). To run R from a terminal, simply run the R command.
Packages
Note - before trying to install a package, first try to load it with the library command. If it isn't installed, then you try to install it. See next...
One of the best features of R is the large number of very good packages that are easy to install and use. Once you have downloaded and installed R and Rstudio and open up Rstudio, you can download and install packages using the install.packages command. For example, here is the command to install openxlsx, you would run the following.
install.packages("openxlsx")
You only need to run this once on your computer. Once it is installed, you use the library command to load the package so it is available for use.
library("openxlsx")
Many packages related to biology and medicine are installed a little differently, using a system called Bioconductor. You first must install the R Bioconductor by running the following.
if (!requireNamespace("BiocManager", quietly = TRUE)) install.packages("BiocManager")
Once this is complete, you can install a Bioconductor package (here the package edgeR) as follows.
BiocManager::install("edgeR")
Case Studies
Read through one of the tutorials, and start looking at each of the following case studies. These are R files that are looking at some interesting data. Our first goal is just to understand what the data is and how the code works. Once we understand how the code works we can ask some more questions about the data.
Gene Expression in Developing Heart Cells
For this example we look at some of the data from a scientific study by researchers looking at heart cell development. The data was downloaded from https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=GSE69618, and the research of the authors was published at https://www.ncbi.nlm.nih.gov/pubmed/26485529. You can also view ISU posters related to looking at this data at http://cs.indstate.edu/info/posters/
Let's take a look at the data and some R code to begin looking at it. Login to one of the CS systems, and run the following commands.
cd ~ mkdir heart-genes cd heart-genes cp /u1/junk/bd4isu/GSE69618_data.csv . cp /u1/junk/bd4isu/GSE69618.R
Open the GSE69618.R file in Rstudio and run each line in the file. Note - your instructor will show you how to do this and explain the different parts of Rstudio that you are seeing.