# Install R libraries

The latest R version is 3.3.2 at the time of writing. Type `R` to start the R environment.

```
R version 3.3.2 (2016-10-31) -- "Sincere Pumpkin Patch"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

>
```

Within the R console, enter following to initiate **Bioconductor**:

```
source("http://bioconductor.org/biocLite.R")
chooseBioCmirror(ind=6)     # Choose "Riken, Kobe (Japan)"
```

## Use biocLite()

To install or update Bioconductor packages [Biobase](http://bioconductor.org/packages/release/bioc/html/Biobase.html) and [qvalue](https://bioconductor.org/packages/release/bioc/html/qvalue.html), and CRAN package [cluster](https://cran.r-project.org/web/packages/cluster/index.html) enters `biocLite(c("cluster","Biobase","qvalue"))`

R will ask you if you wish to install these in your personal library in `~/R`. Type **"y"** to both questions.

```
Would you like to use a personal library instead?  (y/n) y
Would you like to create a personal library
~/R/x86_64-unknown-linux-gnu-library/3.3
to install packages into?  (y/n) y
```

When completed, R will prompt you if you wish to update other packages. Choose **"n"** to skip this step to save time.

```
trying URL 'http://bioconductor.jp/packages/3.4/bioc/src/contrib/BiocInstaller_1.24.0.tar.gz'
Content type 'application/x-gzip' length 17756 bytes (17 Kb)
opened URL
==================================================
downloaded 17 Kb
...
...
...
The downloaded source packages are in
        â€˜/tmp/RtmpAkPtJ1/downloaded_packagesâ€™
Old packages: 'BiocInstaller', 'boot', 'caret', 'class', 'cluster',
  'codetools', 'foreach', 'foreign', 'gdata', 'GenomeInfoDb', 'gplots',
  'gridSVG', 'gtools', 'httpuv', 'iterators', 'KernSmooth', 'lattice', 'lme4',
  'MASS', 'Matrix', 'matrixStats', 'mgcv', 'mime', 'nlme', 'nnet', 'plyr',
  'quantreg', 'R6', 'Rcpp', 'RcppEigen', 'RCurl', 'rpart', 'scales', 'shiny',
  'SparseM', 'spatial', 'stringr', 'survival', 'XML', 'xtable'
Update all/some/none? [a/s/n]: n
```

## Install from source

You can usually use `biocLite()` to install Bioconductor packages. But, if R version you are using is out-dated, the packages that can be installed using `biocLite()` will also be of older versions. Therefore, in this case, you may choose to install the packages from source. Below I showed how you can install [limma](https://bioconductor.org/packages/release/bioc/html/limma.html) and [edgeR](https://bioconductor.org/packages/release/bioc/html/edgeR.html) from package sources from <http://bioconductor.org/>.

To install **limma**, run the following command in R:

```
install.packages("https://bioconductor.org/packages/release/bioc/src/contrib/limma_3.30.2.tar.gz")
```

Install limma v3.30.2 without error:

```
...
...
* installing *source* package ‘limma’ ...
...
...

** R
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded
* DONE (limma)
```

To install **edgeR**, run the following command in R:

```
install.packages("https://bioconductor.org/packages/release/bioc/src/contrib/edgeR_3.16.1.tar.gz")
```

Install edgeR v3.16.1 without error:

```
...
...
* installing *source* package ‘edgeR’ ...
...
...

** R
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded
* DONE (edgeR)
```

Use `sessionInfo()` to print version information about R and attached or loaded packages. This information is useful when providing bug report to package developers.

```
R version 3.3.2 (2016-10-31)
Platform: x86_64-unknown-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C
 [9] LC_ADDRESS=C               LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] BiocInstaller_1.24.0
```

Enter `q()` to exit the R console. Enter **"n"** to not save the workspace as an image.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ycl6.gitbook.io/rna-seq-data-analysis/differential_expression_analysis_using_r/install_r_libraries.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
