---
title: "Install archived Bioconductor packages from previous releases"
author: "Marcel Ramos"
date: "`r format(Sys.time(), '%B %d, %Y')`"
output:
  BiocStyle::html_document:
    number_sections: yes
    toc: true
vignette: >
  %\VignetteIndexEntry{BiocArchive Quick Start}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, setup, include=FALSE}
knitr::opts_chunk$set(cache = TRUE)
```

# BiocArchive

`BiocArchive` is a package dedicated to preserving reproducibility with older
Bioconductor versions. It works for older Bioconductor releases, for example
version `3.14`. Note that users must have the proper `3.14` setup to be able
to install packages from the archive. This means that users should be running
R version `4.1`.

It is highly recommended that users run docker containers with the appropriate
R version installation and install the package via GitHub or via source.

# Installation

Currently, it is available via GitHub. 

```{r,eval=FALSE}
if (!requireNamespace("BiocManager", quietly = TRUE))
    install.packages("BiocManager")

BiocManager::install("Bioconductor/BiocArchive")
```

# Load the package

```{r}
library(BiocArchive)
```

# Last release version

The `lastBuilt` helper function finds the last built date for the supplied
Bioconductor version. Other functions rely on this date to install the
appropriate packages.

```{r}
lastBuilt(version = "3.14")
```

# Archived installations

To install Bioconductor packages from previous releases, we strongly recommend
using Bioconductor Docker containers, where possible. Such containers will have 
`BiocManager` installed. `BiocArchive` allows versioned installations of
[CRAN](https://cran.r-project.org/) packages from either the Posit Public
Package Manager (`P3M`) or the CRAN
[archive](https://cran.r-project.org/src/contrib/Archive/).

## Docker installation

To download the Docker container, one can run the docker command: 

```
docker pull bioconductor/bioconductor_docker:RELEASE_3_14
```

For more information, see the Docker for Bioconductor page: 
https://www.bioconductor.org/help/docker/

## Bioconductor installations

Installations of Bioconductor packages are handled by `BiocManager` and will
work as normal within a legacy container or local installation. 

```{r}
install("DESeq2", version = "3.14", dry.run = TRUE)

install("MultiAssayExperiment", version = "3.14", dry.run = TRUE)
```

__Note__. The `dry.run` argument returns the `CRAN` repository location. The
default is to install `CRAN` packages from the P3M snapshot repository.

# P3M installations

The [Posit Public Package Manager](https://packagemanager.posit.co/client/)
(`P3M`) allows installations of packages from their respective snapshot
repositories. To enable installation from these repositories, users must either
set their `getOption("BiocArchive.snapshot")` option or the `snapshot` argument
to `P3M`. By default, the package uses `P3M` snapshots tied
to the last build date of the Bioconductor version.

```{r}
install("DESeq2", version = "3.14", dry.run = TRUE, snapshot = "P3M")

install(
    "MultiAssayExperiment", version = "3.14", dry.run = TRUE, snapshot = "P3M"
)
```


# CRAN installations from the source archive

Packages on CRAN have a history of versions at a particular URL location:

<https://cran.r-project.org/src/contrib/Archive>

A CRAN package from the archive can be installed (from source) using
`CRANinstall`:

```{r}
CRANinstall("dplyr", "3.14", dry.run = TRUE)
```

The function will attempt to satisfy all dependencies from the CRAN archive.

# Repository URLs

To see the list of active repositories based on option configurations,
use the `repositories()` function:

```{r,eval=FALSE}
repositories(version = "3.14")
```

__Note__. The R version must coincide with the Bioconductor version sought.

# Package validity

To check whether all packages are within the valid time interval of the
Bioconductor release, the `valid()` function will compare package versions
with those in the `P3M` repository.

```{r,eval=FALSE}
valid(version = "3.14")
```

__Note__. The R version must coincide with the Bioconductor version sought.

# Session Information

```{r}
sessionInfo()
```


