• 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 Paths and directories
    • 4.1 Tree of directories
    • 4.2 Navigate the tree of directory with the R console
  • 5 R basics
    • 5.1 Arithmetic operators
    • 5.2 Simple calculations
    • 5.3 Objects in R
    • 5.4 Assignment operators
    • 5.5 Assigning data to an object
    • 5.6 Names of objects
  • 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 ~ 15 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
      • 9.2.1 Exercise 2a.
      • 9.2.2 Exercise 2b.
    • 9.3 Exercise 3. Character vector manipulation
      • 9.3.1 Exercise 3a.
      • 9.3.2 Exercise 3b.
    • 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
    • 11.3 Exercise 6.
      • 11.3.1 Exercise 6a. Input / output
      • 11.3.2 Exercise 6b - I/O on data frames: play with the arguments of read.table
  • 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 7: Library and packages
    • 12.9 Exercise (to do at home)
  • 13 Regular expressions
    • 13.1 Find simple matches with grep
    • 13.2 Regular expressions to find more flexible patterns
    • 13.3 Substitute or remove matching patterns with gsub
    • 13.4 Predefined variables to use in regular expressions:
    • 13.5 Use grep and regular expressions to retrieve columns by their names
    • 13.6 Exercise 8: Regular expressions
  • 14 Conditional statement
    • 14.1 Exercise 9: If statement
  • 15 Repetitive execution
    • 15.1 Exercise 10: For loop
  • 16 “Base” plots in R
    • 16.1 Scatter plots
    • 16.2 Bar plots
    • 16.3 Pie charts
    • 16.4 Box plots
    • 16.5 Histograms
  • 17 How to save plots
    • 17.1 With R Studio
    • 17.2 With the console
    • 17.3 Exercise 11: Base plots
      • 17.3.1 Exercise 11a- scatter plot
      • 17.3.2 Exercise 11b- bar plot + pie chart
      • 17.3.3 Exercise 11c- histogram
  • 18 Plots from other packages
    • 18.1 heatmap.2 function from gplots package
    • 18.2 pheatmap function from the pheatmap package
    • 18.3 venn.diagram function from VennDiagram package
  • 19 ggplot2 package
    • 19.1 Getting started
    • 19.2 Scatter plot
    • 19.3 Box plots
    • 19.4 Dot plots
    • 19.5 Bar plots
      • 19.5.1 Bar plots with error bars
    • 19.6 Histograms
    • 19.7 About themes
    • 19.8 Saving plots in files
    • 19.9 Exercise 12: ggplot2
      • 19.9.1 Exercise 12a- Scatter plot
      • 19.9.2 Exercise 12b- Box plot
      • 19.9.3 Exercise 12c- Bar plot
      • 19.9.4 Exercise 12d- Histogram
    • 19.10 More about the theme() function
    • 19.11 Volcano plots
  • Published with bookdown

Introduction to R

4.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()
  • Change working directory with setwd (set working directory)
    Go to a directory giving the absolute path:
setwd("~/Rcourse")

Go to a directory giving the relative path:

setwd("Module1")

You are now in: “~/Rcourse/Module1”
Move one directory “up” the tree:

setwd("..")

You are now in: “~/Rcourse”