Pre-workshop instructions for R users¶
We encourage participants to use RStudio cloud during this workshop. The features of RStudio cloud map to the features of the desktop application RStudio local which you may be familiar with, with a few minor differences.
To help you get to grips with the main features, a useful RStudio cheat-sheet can be found here, and to learn about the many RStudio cloud features you should go to the online documentation here.
Creating an RStudio Cloud account¶
Please sign up to RStudio Cloud before the workshop and familiarise yourself with it using the tips below.
If you would prefer to use your local copy of RStudio, you will need to install some software, and make sure that they are connected to one another. This may require you to get permission from your IT services department, so it is particularly important that you do this ahead of time.
If you cannot make any part of these instructions work before the session, then please sign up to RStudio Cloud using your GitHub account instead.
Introduction to RStudio Cloud¶
Analysis is organised in Projects¶
Projects keep track of settings tied to a particular data analysis project. When starting a new project you will create a new RStudio Project. If you want to continue working on something, just open up the relevant RStudio Project.
In order open an existing project:
RStudio cloud: your projects will be listed underYour WorkspaceRStudio local: click on the[project_name].Rprojfile in a file browser (your system file browser or theRStudiofile browser); OR through RStudio menus:File>Open Project.../Recent Projects.
Setting up RStudio projects¶
Complete either one of the exercises below, depending on whether you’re using RStudio local/cloud.
You’ll also need to install the required packages so please run the following:
list.of.packages <- c("patchwork", "ggpubr", "tidyverse", "data.table", "knitr", "markdown",
"rmarkdown", "dplyr", "ggplot2", "moments", "car")
new.packages <- list.of.packages[!(list.of.packages %in% installed.packages()[,"Package"])]
if(length(new.packages)) install.packages(new.packages)
Create a new RStudio cloud project¶
Navigate to rstudio.cloud
Navigate to the
Your Workspacetab.Click
New ProjectRename
Untitled Projecttomd-workshop.
Create a new RStudio local project¶
Open RStudio
Select
File>New Project>New Directory>New ProjectDirectory name: “md-workshop”Create project as...: Select a convenient directorySelect
Create Project
Specialised panes have useful features¶
Each pane of RStudio has a special feature which helps you write code and manage your project. Let’s go through them now:
Console- RunsRcommands.Files- File navigator.Terminal- is the same asConsolebut for theBASH/Git BASHshell-language (or whatever shell language is available to you, e.g.,Powershellon Windows). This is useful for managing files and for doing complicated things with version control (not covered in this course). If you haveBASH/Git-BASHtry typingpwdto see what it does.Packages- shows a list of all the packages you have installed.Help- is the help files for all installed packages.Environment- as already mentioned, contains all your saved variables/functions/dataframes etc.History- a list of previously run commands.
Environment¶
Environment shows all the environments that are available to you. This includes all the loaded libraries.
History¶
The history pane shows you all the previous commands that have been run.
This feature of History is particularly useful - you can use it to iteratively build up your R script by: first trying things out in the console and second, easily transfer them to your script when you’re happy with what they do. The History pane is searchable as well so you can add commands from previous sessions.
RStudio has tools for easy code writing and running¶
Other great features are:
tab complete,
multiline editing,
keyboard shortcuts.
Note: the keyboard shortcuts won’t work in RStudio Cloud as they clash with your browser shortcuts.