See the instructions here
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.
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
Lecture0-DirectoryFiles.html Lecture0-DirectoryFiles.Rmd
ASM2019_heterogeneity.pdf Examples of data types hands-on Examples of data types hands-on, the Rmd
The Rmd file is here: DADA2 Workflow Rmd