-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInstructions.Rmd
113 lines (85 loc) · 4.85 KB
/
Instructions.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
---
title: "R Introduction"
author: "Simon Morvan and Benjamin Callahan"
output: slidy_presentation
---
## R Update
We will mainly use two packages during this workshop: [DADA2](https://benjjneb.github.io/dada2/index.html) and [Phyloseq](https://joey711.github.io/phyloseq/index.html). It is recommanded that you update your R software in order that these packages run smoothly. You should have R version **3.5.0 or newer**, and Bioconductor version 3.7 or 3.8. Using Bioconductor is the easiest way to install both DADA2 and Phyloseq. You can check your actual R version by executing the `R.version` command in R.
```{r version, eval=FALSE}
R.version
```
If your version is older than 3.5, follow the next steps. If not, skip to the <span style="color:red"> Installing the packages</span> section.
## For Windows users
```{r win, eval=FALSE}
install.packages("installr")
library(installr)
updateR()
```
What is nice with this package is that it should migrate the packages you've installed on your older version of R to the folder corresponding to the newest version of R. It also updates all the packages you've installed from the CRAN repository.
## For Mac users
```{r mac, eval=FALSE}
install.packages('devtools')
library(devtools)
install_github('andreacirilloac/updateR')
library(updateR)
updateR(admin_password = 'Admin user password')
```
In order to check if everything went according to plan:
```{r checkpack, eval=FALSE}
R.version
```
## For Unix users

[Reference 1](http://bioinfo.umassmed.edu/bootstrappers/bootstrappers-courses/courses/rCourse/Additional_Resources/Updating_R.html) <br>
[Reference 2](https://www.linkedin.com/pulse/3-methods-update-r-rstudio-windows-mac-woratana-ngarmtrakulchol/)
## Installing packages
Now that you've got a brand new R, we're going to install DADA2 and Phyloseq. For that, we must first install the Bioconductor install function `biocLite`.
Old version:
```{r Bioconductor-old, eval=FALSE}
source("https://bioconductor.org/biocLite.R") # Installs Bionconductor
biocLite("dada2") # Installs DADA2
biocLite("phyloseq") # Installs phyloseq
```
In the latest Biocondcutor release they have updated to a new installation solution `BiocManager`:
```{r Bioconductor-new, eval=FALSE}
if (!requireNamespace("BiocManager", quietly = TRUE))
install.packages("BiocManager")
BiocManager::install("dada2", version = "3.8")
BiocManager::install("phyloseq", version = "3.8")
```
If this doesn't work you can try other methods. Methods for [DADA2](https://benjjneb.github.io/dada2/dada-installation.html) and [Phyloseq](https://joey711.github.io/phyloseq/install.html). <br> If you don't succeed, we'll help you out on the first morning of the workshop.
## Getting specific information on a package or function
On R Studio you can type ?'name' or help('name')
For example:
```{r help , eval=FALSE}
library(dada2) # Loads the DADA2 package in the environment
?dada2
?filterAndTrim # One of DADA2's functions
help(filterAndTrim)
```
**This is particularly interesting to understand the parameters the function uses**
You can also see the source code of a function by just typing its name.
```{r code , eval=FALSE}
library(dada2) # Loads the DADA2 package in the environment
filterAndTrim
```
[Reference 3](https://www.r-project.org/help.html)
## 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.
```{r dir , eval=FALSE}
getwd()
setwd("/Users/Jack/Documents/BIOME/")
list.files()
```
## 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.
```{r save , eval=FALSE}
mat <- matrix(sample(0:1, 12, replace=TRUE),3,4) # A 3 by 4 matrix containing 0s and 1s
saveRDS(mat, "Neo") # Save mat with Neo as a file name
the.matrix <- readRDS("Neo") # Load the file Neo 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
```

## Mike Love's Bioconductor "Refcard"
[Refcard](https://github.com/mikelove/bioc-refcard)