• Introduction to R
  • 1 Welcome
  • 2 What is R ?
  • 3 What is RStudio ?
    • 3.1 RStudio access
    • 3.2 RStudio interface
    • 3.3 Setting up the folder structure for the course
      • 3.3.1 Note on files and folders names
  • 4 R basics
    • 4.1 Arithmetic operators
    • 4.2 Simple calculations
    • 4.3 Objects in R
    • 4.4 Assignment operators
    • 4.5 Assigning data to an object
    • 4.6 Using objects
    • 4.7 Names of objects
  • 5 Paths and directories
    • 5.1 Tree of directories
    • 5.2 Navigate the tree of directory with the R console
  • 6 Functions
  • 7 R scripts
    • 7.1 Create and save a script
    • 7.2 R syntax
    • 7.3 RStudio tips in the console
    • 7.4 Exercice 1. Getting started ~ 10 minutes
  • 8 Data types
    • 8.1 Checking data types
  • 9 Data structures
    • 9.1 Vectors
      • 9.1.1 Creating a vector
      • 9.1.2 Vector manipulation
      • 9.1.3 Combining vectors
      • 9.1.4 Numeric vector manipulation
      • 9.1.5 Character vector manipulation
    • 9.2 Exercise 2. Numeric vector manipulation (15 minutes)
      • 9.2.1 Exercise 2a.
      • 9.2.2 Exercise 2b.
    • 9.3 Exercise 3. Character vector manipulation (10 minutes)
    • 9.4 Factors
    • 9.5 Matrices
      • 9.5.1 Creating a matrix
      • 9.5.2 Two-dimensional object
      • 9.5.3 Matrix manipulation
    • 9.6 Data frames
      • 9.6.1 Create a data frame
      • 9.6.2 Data frame manipulation:
    • 9.7 Two-dimensional structures manipulation
      • 9.7.1 Dimensions
      • 9.7.2 Manipulation
    • 9.8 Exercise 4. Matrix manipulation
    • 9.9 Exercise 5. Data frame manipulation
      • 9.9.1 Exercise 5a
      • 9.9.2 Exercise 5b
      • 9.9.3 Exercise 5c
  • 10 Missing values
  • 11 Input / Output
    • 11.1 On vectors
    • 11.2 On data frames or matrices
  • 12 Library and packages
    • 12.1 R base
    • 12.2 R contrib
    • 12.3 Install a package
    • 12.4 Load a package
    • 12.5 Check what packages are currently loaded
    • 12.6 List functions from a package
    • 12.7 RStudio server at CRG
    • 12.8 Exercise 6: about Module 2…
    • 12.9 Workspace
    • 12.10 Exercise 7. Input / output and data selection.
      • 12.10.1 Exercise 7
  • 13 “Base” plots in R
    • 13.1 Scatter plots
    • 13.2 Bar plots
    • 13.3 Pie charts
    • 13.4 Box plots
    • 13.5 Histograms
  • 14 How to save plots
    • 14.1 With R Studio
    • 14.2 With the console
    • 14.3 Exercise 8: Base plots
      • 14.3.1 Exercise 8a- scatter plot
      • 14.3.2 Exercise 8b- bar plot + pie chart
      • 14.3.3 Exercise 8c- histogram
  • 15 Plots from other packages
    • 15.1 pheatmap function from the pheatmap package
    • 15.2 venn.diagram function from VennDiagram package
  • 16 ggplot2 package
    • 16.1 Getting started
    • 16.2 Scatter plot
    • 16.3 Box plots
    • 16.4 Bar plots
      • 16.4.1 Bar plots with error bars
    • 16.5 Histograms
    • 16.6 About themes
    • 16.7 Saving plots in files
    • 16.8 Exercise 9: ggplot2
      • 16.8.1 Exercise 9a- Scatter plot
      • 16.8.2 Exercise 9b- Box plot
      • 16.8.3 Exercise 9c- Bar plot
      • 16.8.4 Exercise 9d- Histogram
    • 16.9 More about the theme() function
    • 16.10 demo: volcano plots
  • 17 Regular expressions
    • 17.1 Find simple matches with grep
    • 17.2 Regular expressions to find more flexible patterns
    • 17.3 Substitute or remove matching patterns with gsub
    • 17.4 Predefined variables to use in regular expressions:
    • 17.5 Use grep and regular expressions to retrieve columns by their names
    • 17.6 Exercise 10: Regular expressions
  • 18 Conditional statement
    • 18.1 Exercise 11: If statement
  • 19 Repetitive execution
    • 19.1 Exercise 12: For loop
  • Published with bookdown

Introduction to R (2021)

5.2 Navigate the tree of directory with the R console

  • Get the path of the current directory (know where you are working at the moment) with getwd (get working directory):
getwd()

Hit Enter/Return to execute getwd() in the R console.

  • Change working directory with setwd (set working directory)
    (in a Windows or MAC OS system, you would typically double-click to reach sub-directories).
    Here we use commands/fonctions in the R console:

Go to a directory giving the absolute path (the entire address):

setwd("/users/bi/sbonnin/Rcourse")

Same as:

setwd("~/Rcourse")

Go to a directory giving the relative path. For example, if you are in Rcourse, you can either go to Module1 using the absolute path:

setwd("/users/bi/sbonnin/Rcourse/Module1")

or the relative path:

setwd("Module1")

You are now in: “~/Rcourse/Module1” (check it with getwd() !).
Move one directory “up” the tree:

setwd("..")

You are now in: “~/Rcourse”

HANDS-ON

  1. Execute the following command in the R console:
setwd("/")
  1. Where are you now? (use getwd())
  2. Find your way back to the Module1 folder