# Installation Guide

## Overview

This guide covers installation, mirror setup, dependency checks, and updates for `evanverse` and related packages.

Area | Tools
--- | ---
Base installation | `install.packages()`, `devtools::install_github()`
Mirror configuration | `set_mirror()`
Installation and checks | `inst_pkg()`, `check_pkg()`
Updates | `update_pkg()`

    library(evanverse)

> Note: All examples are static (`eval = FALSE`). Network-dependent commands require internet access.

## 1 Install evanverse

### CRAN release (recommended)

    install.packages("evanverse")

### GitHub development version

    install.packages("devtools")
    devtools::install_github("evanbio/evanverse")

### Minimal vs full dependency install

    # Minimal: Depends + Imports only
    install.packages("evanverse", dependencies = c("Depends", "Imports"))

    # Full: include Suggests
    install.packages("evanverse", dependencies = TRUE)

## 2 Configure Mirrors

### `set_mirror()` - Configure CRAN/Bioconductor mirrors

`set_mirror()` controls mirror sources used by `inst_pkg()` and `update_pkg()`.

    # Set both CRAN + Bioconductor mirrors (default mirror: tuna)
    set_mirror()
    #> v CRAN mirror set to: https://mirrors.tuna.tsinghua.edu.cn/CRAN
    #> v Bioconductor mirror set to: https://mirrors.tuna.tsinghua.edu.cn/bioconductor

    # CRAN only
    set_mirror("cran", "westlake")

    # Bioconductor only
    set_mirror("bioc", "official")

Supported mirror names:

Scope | Mirrors
--- | ---
CRAN | `official`, `rstudio`, `tuna`, `ustc`, `aliyun`, `sjtu`, `pku`, `hku`, `westlake`, `nju`, `sustech`
Bioconductor | `official`, `tuna`, `ustc`, `westlake`, `nju`

CRAN-only mirrors cannot be used with `repo = "all"`:

    set_mirror("all", "aliyun")
    #> Error in `set_mirror()`:
    #> ! Mirror "aliyun" is CRAN-only and cannot be used with repo = "all".

## 3 Install Other Packages With evanverse

### `inst_pkg()` - Install from CRAN, GitHub, Bioconductor, or local file

    inst_pkg("dplyr", source = "CRAN")

    inst_pkg("hadley/emo", source = "GitHub")

    inst_pkg("DESeq2", source = "Bioconductor")

    inst_pkg(source = "Local", path = "mypackage_1.0.0.tar.gz")

Local installation requires `path`:

    inst_pkg(source = "Local")
    #> Error in `inst_pkg()`:
    #> ! Must provide `path` for local installation.

Already-installed packages are skipped automatically.

## 4 Verify Installation Status

### `check_pkg()` - Check and optionally auto-install missing packages

    check_pkg("ggplot2", source = "CRAN")
    #> # A tibble: 1 x 4
    #>   package name    installed source
    #>   <chr>   <chr>   <lgl>     <chr>
    #> 1 ggplot2 ggplot2 TRUE      CRAN

    check_pkg(c("ggplot2", "fakepkg123"), source = "CRAN")
    #> v Installed: ggplot2
    #> ! Missing: fakepkg123

    check_pkg(c("ggplot2", "fakepkg123"), source = "CRAN", auto_install = TRUE)
    #> i Installing missing packages automatically...

For GitHub source, use `"user/repo"` format:

    check_pkg("r-lib/devtools", source = "GitHub")

## 5 Update Packages

### `update_pkg()` - Update all packages or specific targets

    # Update all CRAN + Bioconductor packages
    update_pkg()

    # CRAN only
    update_pkg(source = "CRAN")

    # Specific package(s)
    update_pkg("ggplot2", source = "CRAN")
    update_pkg("hadley/ggplot2", source = "GitHub")
    update_pkg("DESeq2", source = "Bioconductor")

If `pkg` is provided, `source` must also be provided (cannot stay at `"all"`).

## 6 Troubleshooting

### Package not available

    R.version.string

If your R version is too old, upgrade R and retry.

### Bioconductor install problems

    if (!requireNamespace("BiocManager", quietly = TRUE)) {
      install.packages("BiocManager")
    }
    BiocManager::install(c("Biobase", "GSEABase", "biomaRt", "GEOquery"))

### Corporate network / proxy issues

    Sys.setenv(http_proxy = "http://your-proxy:port")
    Sys.setenv(https_proxy = "https://your-proxy:port")

### Local library permission issues

    install.packages("evanverse", lib = Sys.getenv("R_LIBS_USER"))

## 7 A Combined Workflow

The following sequence is practical for a fresh environment:

    # 1) Install evanverse
    install.packages("evanverse")
    library(evanverse)

    # 2) Set mirrors
    set_mirror("all", "tuna")

    # 3) Install key dependencies
    inst_pkg(c("dplyr", "ggplot2"), source = "CRAN")
    inst_pkg("DESeq2", source = "Bioconductor")

    # 4) Verify status
    check_pkg(c("dplyr", "ggplot2", "DESeq2"), source = "CRAN")

    # 5) Keep packages updated
    update_pkg(source = "CRAN")

## Getting Help

- `?set_mirror`, `?inst_pkg`, `?check_pkg`, `?update_pkg`
- CRAN Package Page
- GitHub Issues