Contents

Downloading and installation

See the instructions here

Setting and checking your directory

Whenever you’re launching R, it selects a default directory (i.e a file in which you can save your script, your objects). The function getwd will give you the path to the directory you are in. In order to change it, the function setwd is used. You have to specify the path to the directory you want. Another usefull function is list.files which will return all the files present in the directory you’re in.

getwd()
setwd("/Users/Serina/SelfStudy/ASM/")
list.files()

Note: It is actually worth your time to use the here package and create a new R project:

install.packages("here")
here("data", "file_wanted.csv")

see the recommendation by Jenny Bryan here.

Saving and loading your objects

When you run a pipeline or analysis, it is convenient to save the objects such as matrices or dataframes. By doing so, you won’t have to run your analysis every single time you want to view the object in question. In order to save an object the function saveRDS can be used. The object can then be opened with the readRDS function. This pair of functions are an alternative to the save and load. Their adventage is to allow the user to give a new name to the saved object when they load it.

mat <- matrix(sample(0:1, 12, replace=TRUE),3,4) # A 3 by 4 matrix containing 0s and 1s
saveRDS(mat, "nem.rds") # Save mat with Neo as a file name 
the.matrix <- readRDS("nem.rds") # Load the file nem.rds but it will no longer be named mat but the.matrix in your environment
identical(mat, the.matrix ) # Checks if mat and my.matrix are identical

Preliminary manipulations in R

Lecture0-DirectoryFiles.html Lecture0-DirectoryFiles.Rmd

Exact ASVs and DADA2:

Exact ASVs Lecture pdf

Phyloseq

Link to Phyloseq Lab html
Link to Phyloseq Lab Rmd

Dimension Reduction

Multivariate Analysis 101
A book chapter

Robust Methods