2 Installation

This chapter provides installation instructions for R and RStudio (developing environment, user interface) on your local system.

2.1 Install R

  • Follow link on website for your operating system link
  • Select CRAN
  • Comprehensive R Archive Network (CRAN) is a collection of sites which carry identical material, consisting of the R distribution(s), the contributed extensions, documentation for R, and binaries.

2.2 Install RStudio

  • Download community/open-source version for free on website link
  • RStudio is an integrated development environment (IDE) for R that provides an alternative interface to R
  • RStudio provides integrated support for editing and executing R code and documents.
  • Divided into 4 panes
  • Read more about RStudio link
  • Write code interactively in console pane and make scripts in program pane
  • Practice: the Workspace link

2.3 Terms

  • Path = the route to a file (file = file or folder)
  • Absolute path = the route starts at home node e.g. /home/Documents/myReport (mac) or C:(windows), C:.txt
  • Relative path = refers to file that you can access if you start at current working directory e.g starting in the home folder: Documents/myReport
  • Read more: What Is a Path? link
  • Directory = folder
  • Working directory = which folder are you/R currently working in? When you import or export files using a relative path, it will be relative to this working directory.
  • Script = a list of commands that are executed by a certain program, saved as files with extension “.R”. Save code in the scripting area and run chunks or all code.
  • Command = instruction given by a user telling a computer to do something. Commands are given to R / implemented using functions (code to execute instructions).

Examples of commands:

  • getwd() # print your current working directory
  • setwd(a_path) # sets your working directory
  • q() # quit

Type commands in RStudio in the program pane (also called console) starting at the >.

# Get working directory
getwd()
## [1] "C:/Users/Khokha lab/Documents/GitHub/learn-r"
# Paths
path = "Documents"  #relative path
path = "C:/Users/YourName/Documents" #absolute path
# # Set working directory
# setwd(path) # equivalent to setwd( "C:/Users/YourName/Documents")