---
title: "Introduction to R"
author: "Author: Thomas Girke"
date: "Last update: `r format(Sys.time(), '%d %B, %Y')`"
output:
BiocStyle::html_document:
toc: true
toc_depth: 3
fig_caption: yes
fontsize: 14pt
bibliography: bibtex.bib
---
```{r style, echo = FALSE, results = 'asis'}
BiocStyle::markdown()
options(width=100, max.print=1000)
knitr::opts_chunk$set(
eval=as.logical(Sys.getenv("KNITR_EVAL", "TRUE")),
cache=as.logical(Sys.getenv("KNITR_CACHE", "TRUE")))
```
```{r setup, echo=FALSE, messages=FALSE, warnings=FALSE}
suppressPackageStartupMessages({
library(limma)
library(ggplot2) })
```
# Overview
## What is R?
[R](http://cran.at.r-project.org) is a powerful statistical environment and
programming language for the analysis and visualization of data. The
associated [Bioconductor](http://bioconductor.org/) and CRAN package
repositories provide many additional R packages for statistical data analysis
for a wide array of research areas. The R software is free and runs on all
common operating systems.
## Why Using R?
* Complete statistical environment and programming language
* Efficient functions and data structures for data analysis
* Powerful graphics
* Access to fast growing number of analysis packages
* Most widely used language in bioinformatics
* Is standard for data mining and biostatistical analysis
* Technical advantages: free, open-source, available for all OSs
## Books and Documentation
* simpleR - Using R for Introductory Statistics (John Verzani, 2004) - [URL](http://cran.r-project.org/doc/contrib/Verzani-SimpleR.pdf)
* Bioinformatics and Computational Biology Solutions Using R and Bioconductor (Gentleman et al., 2005) - [URL](http://www.bioconductor.org/help/publications/books/bioinformatics-and-computational-biology-solutions/)
* More on this see "Finding Help" section in UCR Manual - [URL](http://manuals.bioinformatics.ucr.edu/home/R\_BioCondManual\#TOC-Finding-Help)
## R Working Environments
## Working environments (IDEs) for R
R Projects and Interfaces
Some R working environments with support for syntax highlighting and utilities to send code
to the R console:
* [RStudio](https://www.rstudio.com/products/rstudio/features): excellent choice for beginners ([Cheat Sheet](http://www.rstudio.com/wp-content/uploads/2016/01/rstudio-IDE-cheatsheet.pdf))
* Basic R code editors provided by Rguis
* [gedit](https://wiki.gnome.org/Apps/Gedit), [Rgedit](http://rgedit.sourceforge.net/), [RKWard](https://rkward.kde.org/), [Eclipse](http://www.walware.de/goto/statet), [Tinn-R](http://www.sciviews.org/Tinn-R/), [Notepad++](https://notepad-plus-plus.org/), [NppToR](http://sourceforge.net/projects/npptor/)
* [Vim-R-Tmux](http://manuals.bioinformatics.ucr.edu/home/programming-in-r/vim-r): R working environment based on vim and tmux
* [Emacs](http://www.xemacs.org/Download/index.html) ([ESS add-on package](http://ess.r-project.org/))
### Example: RStudio
New integrated development environment (IDE) for [R](http://www.rstudio.com/ide/download/). Highly functional for both beginners and
advanced.
RStudio IDE
Some userful shortcuts: `Ctrl+Enter` (send code), `Ctrl+Shift+C` (comment/uncomment), `Ctrl+1/2` (switch window focus)
### Example: Vim-R-Tmux
Terminal-based Working Environment for R: [Vim-R-Tmux](http://manuals.bioinformatics.ucr.edu/home/programming-in-r/vim-r)
Vim-R-Tmux IDE for R
# R Package Repositories
* CRAN (>8,000 packages) general data analysis - [URL](http://cran.at.r-project.org/)
* Bioconductor (>1,100 packages) bioscience data analysis - [URL](http://www.bioconductor.org/)
* Omegahat (>90 packages) programming interfaces - [URL](https://github.com/omegahat?tab=repositories)
# Installation of R and Add-on Packages
(1.) Install R for your operating system from [CRAN](http://cran.at.r-project.org/).
(2.) Install RStudio from [RStudio](http://www.rstudio.com/ide/download).
(3.) Install CRAN Packages from R console like this:
```{r install_cran, eval=FALSE}
install.packages(c("pkg1", "pkg2"))
install.packages("pkg.zip", repos=NULL)
```
(4.) Install Bioconductor packages as follows:
```{r install_bioc, eval=FALSE}
source("http://www.bioconductor.org/biocLite.R")
library(BiocInstaller)
BiocVersion()
biocLite()
biocLite(c("pkg1", "pkg2"))
```
(5.) For more details consult the [Bioc Install page](http://www.bioconductor.org/install/)
and [BiocInstaller](http://www.bioconductor.org/packages/release/bioc/html/BiocInstaller.html) package.
# Getting Around
## Startup and Closing Behavior
* __Starting R__:
The R GUI versions, including RStudio, under Windows and Mac OS X can be
opened by double-clicking their icons. Alternatively, one can start it by
typing `R` in a terminal (default under Linux).
* __Startup/Closing Behavior__:
The R environment is controlled by hidden files in the startup directory:
`.RData`, `.Rhistory` and `.Rprofile` (optional).
* __Closing R__:
```{r closing_r, eval=FALSE}
q()
```
```
Save workspace image? [y/n/c]:
```
* __Note__:
When responding with `y`, then the entire R workspace will be written to
the `.RData` file which can become very large. Often it is sufficient to just
save an analysis protocol in an R source file. This way one can quickly
regenerate all data sets and objects.
## Navigating directories
Create an object with the assignment operator `<-` or `=`
```{r r_assignment, eval=FALSE}
object <- ...
```
List objects in current R session
```{r r_ls, eval=FALSE}
ls()
```
Return content of current working directory
```{r r_dirshow, eval=FALSE}
dir()
```
Return path of current working directory
```{r r_dirpath, eval=FALSE}
getwd()
```
Change current working directory
```{r r_setwd, eval=FALSE}
setwd("/home/user")
```
# Basic Syntax
General R command syntax
```{r r_syntax, eval=FALSE}
object <- function_name(arguments)
object <- object[arguments]
```
Finding help
```{r r_find_help, eval=FALSE}
?function_name
```
Load a library/package
```{r r_package_load, eval=FALSE}
library("my_library")
```
List functions defined by a library
```{r r_package_functions, eval=FALSE}
library(help="my_library")
```
Load library manual (PDF or HTML file)
```{r r_load_vignette, eval=FALSE}
vignette("my_library")
```
Execute an R script from within R
```{r r_execute_script, eval=FALSE}
source("my_script.R")
```
Execute an R script from command-line (the first of the three options is preferred)
```{sh sh_execute_script, eval=FALSE}
$ Rscript my_script.R
$ R CMD BATCH my_script.R
$ R --slave < my_script.R
```
# Data Types
## Numeric data
Example: `1, 2, 3, ...`
```{r r_numeric_data, eval=TRUE}
x <- c(1, 2, 3)
x
is.numeric(x)
as.character(x)
```
## Character data
Example: `"a", "b", "c", ...`
```{r r_character_data, eval=TRUE}
x <- c("1", "2", "3")
x
is.character(x)
as.numeric(x)
```
## Complex data
Example: mix of both
```{r r_complex_data, eval=TRUE}
c(1, "b", 3)
```
## Logical data
Example: `TRUE` of `FALSE`
```{r r_logical_data, eval=TRUE}
x <- 1:10 < 5
x
!x
which(x) # Returns index for the 'TRUE' values in logical vector
```
# Data objects
## Object types
## Vectors (1D)
Definition: `numeric` or `character`
```{r r_vector_object, eval=TRUE}
myVec <- 1:10; names(myVec) <- letters[1:10]
myVec[1:5]
myVec[c(2,4,6,8)]
myVec[c("b", "d", "f")]
```
## Factors (1D)
Definition: vectors with grouping information
```{r r_factor_object, eval=TRUE}
factor(c("dog", "cat", "mouse", "dog", "dog", "cat"))
```
## Matrices (2D)
Definition: two dimensional structures with data of same type
```{r r_matrix_object, eval=TRUE}
myMA <- matrix(1:30, 3, 10, byrow = TRUE)
class(myMA)
myMA[1:2,]
myMA[1, , drop=FALSE]
```
## Data Frames (2D)
Definition: two dimensional objects with data of variable types
```{r r_dataframe_object, eval=TRUE}
myDF <- data.frame(Col1=1:10, Col2=10:1)
myDF[1:2, ]
```
## Arrays
Definition: data structure with one, two or more dimensions
## Lists
Definition: containers for any object type
```{r r_list_object, eval=TRUE}
myL <- list(name="Fred", wife="Mary", no.children=3, child.ages=c(4,7,9))
myL
myL[[4]][1:2]
```
## Functions
Definition: piece of code
```{r r_function_object, eval=FALSE}
myfct <- function(arg1, arg2, ...) {
function_body
}
```
## Subsetting of data objects
__(1.) Subsetting by positive or negative index/position numbers__
```{r r_subset_by_index, eval=TRUE}
myVec <- 1:26; names(myVec) <- LETTERS
myVec[1:4]
```
__(2.) Subsetting by same length logical vectors__
```{r r_subset_by_logical, eval=TRUE}
myLog <- myVec > 10
myVec[myLog]
```
__(3.) Subsetting by field names__
```{r r_subset_by_names, eval=TRUE}
myVec[c("B", "K", "M")]
```
__(4.) Subset with `$` sign__: references a single column or list component by its name
```{r r_subset_by_dollar, eval=TRUE}
iris$Species[1:8]
```
# Important Utilities
## Combining Objects
The `c` function combines vectors and lists
```{r r_combine_vectors, eval=TRUE}
c(1, 2, 3)
x <- 1:3; y <- 101:103
c(x, y)
iris$Species[1:8]
```
The `cbind` and `rbind` functions can be used to append columns and rows, respecively.
```{r r_cbind_rbind, eval=TRUE}
ma <- cbind(x, y)
ma
rbind(ma, ma)
```
## Accessing Dimensions of Objects
Length and dimension information of objects
```{r r_length_dim, eval=TRUE}
length(iris$Species)
dim(iris)
```
## Accessing Name Slots of Objects
Accessing row and column names of 2D objects
```{r col_row_names, eval=TRUE}
rownames(iris)[1:8]
colnames(iris)
```
Return name field of vectors and lists
```{r name_slots, eval=TRUE}
names(myVec)
names(myL)
```
## Sorting Objects
The function `sort` returns a vector in ascending or descending order
```{r sort_objects, eval=TRUE}
sort(10:1)
```
The function `order` returns a sorting index for sorting an object
```{r order_objects, eval=TRUE}
sortindex <- order(iris[,1], decreasing = FALSE)
sortindex[1:12]
iris[sortindex,][1:2,]
sortindex <- order(-iris[,1]) # Same as decreasing=TRUE
```
Sorting multiple columns
```{r order_columns, eval=TRUE}
iris[order(iris$Sepal.Length, iris$Sepal.Width),][1:2,]
```
# Operators and Calculations
## Comparison Operators
Comparison operators: `==`, `!=`, `<`, `>`, `<=`, `>=`
```{r comparison_operators, eval=TRUE}
1==1
```
Logical operators: AND: `&`, OR: `|`, NOT: `!`
```{r logical_operators, eval=TRUE}
x <- 1:10; y <- 10:1
x > y & x > 5
```
## Basic Calculations
To look up math functions, see Function Index [here](http://cran.at.r-project.org/doc/manuals/R-intro.html#Function-and-variable-index)
```{r logical_calculations, eval=TRUE}
x + y
sum(x)
mean(x)
apply(iris[1:6,1:3], 1, mean)
```
# Reading and Writing External Data
## Import of tabular data
Import of a tab-delimited tabular file
```{r read_delim, eval=FALSE}
myDF <- read.delim("myData.xls", sep="\t")
```
Import of Excel file. Note: working with tab- or comma-delimited files is more flexible and preferred.
```{r read_excel, eval=FALSE}
library(gdata)
myDF <- read.xls"myData.xls")
```
Import of Google Sheets. The following example imports a sample Google Sheet from [here](https://docs.google.com/spreadsheets/d/1U-32UcwZP1k3saKeaH1mbvEAOfZRdNHNkWK2GI1rpPM/edit#gid=472150521).
Detailed instructions for interacting from R with Google Sheets with the required `googlesheets` package are [here](https://github.com/jennybc/googlesheets).
```{r read_gs, eval=FALSE}
library("googlesheets"); library("dplyr"); library(knitr)
gs_auth() # Creates authorizaton token (.httr-oauth) in current directory if not present
sheetid <-"1U-32UcwZP1k3saKeaH1mbvEAOfZRdNHNkWK2GI1rpPM"
gap <- gs_key(sheetid)
mysheet <- gs_read(gap, skip=4)
myDF <- as.data.frame(mysheet)
myDF
```
## Export of tabular data
```{r write_table, eval=FALSE}
write.table(myDF, file="myfile.xls", sep="\t", quote=FALSE, col.names=NA)
```
## Line-wise import
```{r readlines, eval=FALSE}
myDF <- readLines("myData.txt")
```
## Line-wise export
```{r writelines, eval=FALSE}
writeLines(month.name, "myData.txt")
```
## Copy and paste into R
On Windows/Linux systems
```{r paste_windows, eval=FALSE}
read.delim("clipboard")
```
On Mac OS X systems
```{r paste_osx, eval=FALSE}
read.delim(pipe("pbpaste"))
```
## Copy and paste from R
On Windows/Linux systems
```{r copy_windows, eval=FALSE}
write.table(iris, "clipboard", sep="\t", col.names=NA, quote=F)
```
On Mac OS X systems
```{r copy_osx, eval=FALSE}
zz <- pipe('pbcopy', 'w')
write.table(iris, zz, sep="\t", col.names=NA, quote=F)
close(zz)
```
## Homework 3A
Homework 3A: [Object Subsetting Routines and Import/Export](http://girke.bioinformatics.ucr.edu/GEN242/mydoc/mydoc_homework_03.html)
# Useful R Functions
## Unique entries
Make vector entries unique with `unique`
```{r unique, eval=TRUE}
length(iris$Sepal.Length)
length(unique(iris$Sepal.Length))
```
## Count occurrences
Count occurrences of entries with `table`
```{r table, eval=TRUE}
table(iris$Species)
```
## Aggregate data
Compute aggregate statistics with `aggregate`
```{r aggregate, eval=TRUE}
aggregate(iris[,1:4], by=list(iris$Species), FUN=mean, na.rm=TRUE)
```
## Intersect data
Compute intersect between two vectors with `%in%`
```{r intersect, eval=TRUE}
month.name %in% c("May", "July")
```
## Merge data frames
Join two data frames by common field entries with `merge` (here row names `by.x=0`). To obtain only the common rows, change `all=TRUE` to `all=FALSE`. To merge on specific columns, refer to them by their position numbers or their column names.
```{r merge, eval=TRUE}
frame1 <- iris[sample(1:length(iris[,1]), 30), ]
frame1[1:2,]
dim(frame1)
my_result <- merge(frame1, iris, by.x = 0, by.y = 0, all = TRUE)
dim(my_result)
```
# SQLite Databases
`SQLite` is a lightweight relational database solution. The `RSQLite` package provides an easy to use interface to create, manage and query `SQLite` databases directly from R. Basic instructions
for using `SQLite` from the command-line are available [here](https://www.sqlite.org/cli.html). A short introduction to `RSQLite` is available [here](https://github.com/rstats-db/RSQLite/blob/master/vignettes/RSQLite.Rmd).
## Loading data into SQLite databases
The following loads two `data.frames` derived from the `iris` data set (here `mydf1` and `mydf2`)
into an SQLite database (here `test.db`).
```{r load_sqlite, eval=TRUE}
library(RSQLite)
mydb <- dbConnect(SQLite(), "test.db") # Creates database file test.db
mydf1 <- data.frame(ids=paste0("id", seq_along(iris[,1])), iris)
mydf2 <- mydf1[sample(seq_along(mydf1[,1]), 10),]
dbWriteTable(mydb, "mydf1", mydf1)
dbWriteTable(mydb, "mydf2", mydf2)
```
## List names of tables in database
```{r list_tables, eval=TRUE}
dbListTables(mydb)
```
## Import table into `data.frame`
```{r import_sqlite_tables, eval=TRUE}
dbGetQuery(mydb, 'SELECT * FROM mydf2')
```
## Query database
```{r query_sqlite_tables, eval=TRUE}
dbGetQuery(mydb, 'SELECT * FROM mydf1 WHERE "Sepal.Length" < 4.6')
```
## Join tables
The two tables can be joined on the shared `ids` column as follows.
```{r join_sqlite_tables, eval=TRUE}
dbGetQuery(mydb, 'SELECT * FROM mydf1, mydf2 WHERE mydf1.ids = mydf2.ids')
```
# R Markdown
## Overview
R Markdown combines markdown (an easy to write plain text format) with embedded
R code chunks. When compiling R Markdown documents, the code components can be
evaluated so that both the code and its output can be included in the final
document. This makes analysis reports highly reproducible by allowing to automatically
regenerate them when the underlying R code or data changes. R Markdown
documents (`.Rmd` files) can be rendered to various formats including HTML and
PDF. The R code in an `.Rmd` document is processed by `knitr`, while the
resulting `.md` file is rendered by `pandoc` to the final output formats
(_e.g._ HTML or PDF). Historically, R Markdown is an extension of the older
`Sweave/Latex` environment. Rendering of mathematical expressions and reference
management is also supported by R Markdown using embedded Latex syntax and
Bibtex, respectively.
## Quick Start
### Install R Markdown
```{r install_rmarkdown, eval=FALSE}
install.packages("rmarkdown")
```
### Initialize a new R Markdown (`Rmd`) script
To minimize typing, it can be helful to start with an R Markdown template and
then modify it as needed. Note the file name of an R Markdown scirpt needs to
have the extension `.Rmd`. Template files for the following examples are available
here:
+ R Markdown sample script: [`sample.Rmd`](https://raw.githubusercontent.com/tgirke/GEN242/master/vignettes/07_Rbasics/sample.Rmd)
+ Bibtex file for handling citations and reference section: [`bibtex.bib`](https://raw.githubusercontent.com/tgirke/GEN242/master/vignettes/07_Rbasics/bibtex.bib)
Users want to download these files, open the `sample.Rmd` file with their preferred R IDE
(_e.g._ RStudio, vim or emacs), initilize an R session and then direct their R session to
the location of these two files.
### Metadata section
The metadata section (YAML header) in an R Markdown script defines how it will be processed and
rendered. The metadata section also includes both title, author, and date information as well as
options for customizing the output format. For instance, PDF and HTML output can be defined
with `pdf_document` and `html_document`, respectively. The `BiocStyle::` prefix will use the
formatting style of the [`BiocStyle`](http://bioconductor.org/packages/release/bioc/html/BiocStyle.html)
package from Bioconductor.
```
---
title: "My First R Markdown Document"
author: "Author: First Last"
date: "Last update: `r format(Sys.time(), '%d %B, %Y')`"
output:
BiocStyle::html_document:
toc: true
toc_depth: 3
fig_caption: yes
fontsize: 14pt
bibliography: bibtex.bib
---
```
### Render `Rmd` script
An R Markdown script can be evaluated and rendered with the following `render` command or by pressing the `knit` button in RStudio.
The `output_format` argument defines the format of the output (_e.g._ `html_document`). The setting `output_format="all"` will generate
all supported output formats. Alternatively, one can specify several output formats in the metadata section as shown in the above example.
```{r render_rmarkdown, eval=FALSE, message=FALSE}
rmarkdown::render("sample.Rmd", clean=TRUE, output_format="html_document")
```
The following shows two options how to run the rendering from the command-line.
```{sh render_commandline, eval=FALSE, message=FALSE}
$ echo "rmarkdown::render('sample.Rmd', clean=TRUE)" | R --slave
$ Rscript -e "rmarkdown::render('sample.Rmd', clean=TRUE)"
```
Alternatively, one can use a Makefile to evaluate and render an R Markdown
script. A sample Makefile for rendering the above `sample.Rmd` can be
downloaded [`here`](https://raw.githubusercontent.com/tgirke/GEN242/master/vignettes/07_Rbasics/Makefile).
To apply it to a custom `Rmd` file, one needs open the Makefile in a text
editor and change the value assigned to `MAIN` (line 13) to the base name of
the corresponding `.Rmd` file (_e.g._ assign `systemPipeRNAseq` if the file
name is `systemPipeRNAseq.Rmd`). To execute the `Makefile`, run the following
command from the command-line.
```{sh render_makefile, eval=FALSE, message=FALSE}
$ make -B
```
### R code chunks
R Code Chunks can be embedded in an R Markdown script by using three backticks
at the beginning of a new line along with arguments enclosed in curly braces
controlling the behavior of the code. The following lines contain the
plain R code. A code chunk is terminated by a new line starting with three backticks.
The following shows an example of such a code chunk. Note the backslashes are
not part of it. They have been added to print the code chunk syntax in this document.
```
```\{r code_chunk_name, eval=FALSE\}
x <- 1:10
```
```
The following lists the most important arguments to control the behavior of R code chunks:
+ `r`: specifies language for code chunk, here R
+ `chode_chunk_name`: name of code chunk; this name needs to be unique
+ `eval`: if assigned `TRUE` the code will be evaluated
+ `warning`: if assigned `FALSE` warnings will not be shown
+ `message`: if assigned `FALSE` messages will not be shown
+ `cache`: if assigned `TRUE` results will be cached to reuse in future rendering instances
+ `fig.height`: allows to specify height of figures in inches
+ `fig.width`: allows to specify width of figures in inches
For more details on code chunk options see [here](https://www.rstudio.com/wp-content/uploads/2015/03/rmarkdown-reference.pdf).
### Learning Markdown
The basic syntax of Markdown and derivatives like kramdown is extremely easy to learn. Rather
than providing another introduction on this topic, here are some useful sites for learning Markdown:
+ [Markdown Intro on GitHub](https://guides.github.com/features/mastering-markdown/)
+ [Markdown Cheet Sheet](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet)
+ [Markdown Basics from RStudio](http://rmarkdown.rstudio.com/authoring_basics.html)
+ [R Markdown Cheat Sheet](http://www.rstudio.com/wp-content/uploads/2015/02/rmarkdown-cheatsheet.pdf)
+ [kramdown Syntax](http://kramdown.gettalong.org/syntax.html)
### Tables
There are several ways to render tables. First, they can be printed within the R code chunks. Second,
much nicer formatted tables can be generated with the functions `kable`, `pander` or `xtable`. The following
example uses `kable` from the `knitr` package.
```{r kable}
library(knitr)
kable(iris[1:12,])
```
### Figures
Plots generated by the R code chunks in an R Markdown document can be automatically
inserted in the output file. The size of the figure can be controlled with the `fig.height`
and `fig.width` arguments.
```{r some_jitter_plot, eval=TRUE}
library(ggplot2)
dsmall <- diamonds[sample(nrow(diamonds), 1000), ]
ggplot(dsmall, aes(color, price/carat)) + geom_jitter(alpha = I(1 / 2), aes(color=color))
```
Sometimes it can be useful to explicitly write an image to a file and then insert that
image into the final document by referencing its file name in the R Markdown source. For
instance, this can be useful for time consuming analyses. The following code will generate a
file named `myplot.png`. To insert the file in the final document, one can use standard
Markdown or HTML syntax, _e.g._: ``.
```{r some_custom_inserted_plot, eval=TRUE, warning=FALSE, message=FALSE}
png("myplot.png")
ggplot(dsmall, aes(color, price/carat)) + geom_jitter(alpha = I(1 / 2), aes(color=color))
dev.off()
```
### Inline R code
To evaluate R code inline, one can enclose an R expression with a single back-tick
followed by `r` and then the actual expression. For instance, the back-ticked version
of 'r 1 + 1' evaluates to `r 1 + 1` and 'r pi' evaluates to `r pi`.
### Mathematical equations
To render mathematical equations, one can use standard Latex syntax. When expressions are
enclosed with single `$` signs then they will be shown inline, while
enclosing them with double `$$` signs will show them in display mode. For instance, the following
Latex syntax `d(X,Y) = \sqrt[]{ \sum_{i=1}^{n}{(x_{i}-y_{i})^2} }` renders in display mode as follows:
$$d(X,Y) = \sqrt[]{ \sum_{i=1}^{n}{(x_{i}-y_{i})^2} }$$
### Citations and bibliographies
Citations and bibliographies can be autogenerated in R Markdown in a similar
way as in Latex/Bibtex. Reference collections should be stored in a separate
file in Bibtex or other supported formats. To cite a publication in an R Markdown
script, one uses the syntax `[@]` where `` needs to be replaced with a
reference identifier present in the Bibtex database listed in the metadata section
of the R Markdown script (_e.g._ `bibtex.bib`). For instance, to cite Lawrence et al.
(2013), one uses its reference identifier (_e.g._ `Lawrence2013-kt`) as `` [@Lawrence2013-kt].
This will place the citation inline in the text and add the corresponding
reference to a reference list at the end of the output document. For the latter a
special section called `References` needs to be specified at the end of the R Markdown script.
To fine control the formatting of citations and reference lists, users want to consult this
the corresponding [R Markdown page](http://rmarkdown.rstudio.com/authoring_bibliographies_and_citations.html).
Also, for general reference management and outputting references in Bibtex format [Paperpile](https://paperpile.com/features)
can be very helpful.
# Session Info
```{r sessionInfo}
sessionInfo()
```
# References