Open RStudio and create a new project, for more info see https://support.rstudio.com/hc/en-us/articles/200526207-Using-Projects
Learn more about packrat see https://rstudio.github.io/packrat/
Set some options and make sure the packages ‘knitr’, ‘tidyverse’, ‘reshape2’, and ’gr are installed (if not install it), and then load
In the R console run the following commands
if (!any(rownames(installed.packages()) == "knitr")){
  install.packages("knitr")
}
library(knitr)
if (!any(rownames(installed.packages()) == "tidyverse")){
  install.packages("tidyverse")
}
library(tidyverse)## ── Attaching packages ───────────────────────────── tidyverse 1.2.1 ──## ✔ ggplot2 2.2.1     ✔ purrr   0.2.4
## ✔ tibble  1.4.2     ✔ dplyr   0.7.4
## ✔ tidyr   0.8.0     ✔ stringr 1.3.0
## ✔ readr   1.1.1     ✔ forcats 0.3.0## ── Conflicts ──────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()if (!any(rownames(installed.packages()) == "reshape2")){
  install.packages("reshape2")
}
library(reshape2)## 
## Attaching package: 'reshape2'## The following object is masked from 'package:tidyr':
## 
##     smithsif (!any(rownames(installed.packages()) == "gridExtra")){
  install.packages("gridExtra")
}
library(gridExtra)## 
## Attaching package: 'gridExtra'## The following object is masked from 'package:dplyr':
## 
##     combineLearn more about the tidyverse see https://www.tidyverse.org.
An R notebook is an R Markdown document with chunks that can be executed independently and interactively, with output visible immediately beneath the input. More info see https://rmarkdown.rstudio.com/r_notebooks.html
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the preview or Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed R code and plots in chunks like this:
```{r chunk_name}
print('hello world!')
```Review the R Markdown page and R Markdown cheat sheets.
Try ‘knitting’ to html, pdf, and doc as well as previewing the notebook. Open the resulting documents.
Try executing the code chunks in the R Notebook.
This is the stats file generated after running samtools stats on a bam file generated from running BWA MEM.
In the R console run the following command.
download.file("https://raw.githubusercontent.com/ucdavis-bioinformatics-training/2018-March-Bioinformatics-Prerequisites/master/Data_in_R/bwa_mem_Stats.log", "bwa_mem_Stats.log")In the R console run the following command
download.file("https://raw.githubusercontent.com/ucdavis-bioinformatics-training/2018-March-Bioinformatics-Prerequisites/master/Data_in_R/data_in_R.Rmd", "data_in_R.Rmd")The top YAML (YAML ain’t markup language) portion of the doc tells RStudio how to parse the document.
---
title: "Data_in_R"
author: your_name
date: current_date
output:
    html_notebook: default
    html_document: default
---We will recreate some of the plots generated with plot-bamstats on the same file
You can view the output of plot-bamstats -> https://rawgit.com/ucdavis-bioinformatics-training/2018-March-Bioinformatics-Prerequisites/master/Data_in_R/bwa_mem_Stats/bwa_mem_Stats.html