We recommend using RStudio for this workshop. RStudio is an Integrated Development Environment (IDE) for R. It can be accessed in several ways. Download RStudio and install it on your own computer.
The are 4 main panes, each with several tabs:
You can cutomise the appearance of RStudio under the Tools -> Global Options… menu.
There is a drop-down project menu at the top right of RStudio. Click this, select “New Project…” and create one in a new directory. Make sure you have write permission for the directory you choose.
Once you have done this, this will be your working directory. Files will be saved (or loaded from) here by default unless you specify a full path. You can change your working directory under the session menu at the top.
Using Rstudio has the advantage that everything you do can be saved between RStudio sessions.
You can work in 3 different ways in RStudio.
Commands can be typed directly into the console, but in order to keep track it’s best to write them into a script as you go (File->New File->R Script). From here you can use a shortcut to run the command on the line where your cursor is:
You can also use the Tab key to autocomplete names of functions and objects as you type them into your script.
Hint: When using the console, the Up/Down arrow keys can be use to cycle through previous commands.
In the console you should always see a >
prompt, if
you can’t see this R may still be working. There is a red Stop light at
the top right of the console when a command is running. If you see a
+
instead of >
, R is waiting for more
input. Sometimes this means you have forgotten to close a bracket or
quotation.
Using R Markdown is a great way to annotate your code and present an analysis with code, figures and text all together in a web page or document format. It’s worth learning but adds a further level of complication for novice users so is not covered in this course.
Libraries provide additional functions in R and can be downloaded from several sources:
Install the packages we need for these lessons by running the code below in the R console:
#install from CRAN with install.packages()
install.packages(c("tidyverse", "ggthemes", "plotly","ggpubr", "ggrepel","viridis","RColorBrewer","ggsci","patchwork","gghighlight","rstatix"))
#Example to install from bioconductor with BiocManager
#if (!requireNamespace("BiocManager", quietly = TRUE))
# install.packages("BiocManager")
#BiocManager::install(c("DESeq2","genomation"))
#Example to install from github with the devtools package
#install.packages("devtools")
#devtools::install_github("thomasp85/patchwork")
To load a specific package within an R session, use the
library
function:
library(tidyverse)