Switchr

Unlike Python’s virtualenv or conda , R lacks a first-class, built-in mechanism for per-project library stacks. Switchr fills this gap by providing programmatic switching between sets of installed packages (called "sandboxes" or "library stacks" ). It allows you to maintain, e.g., a "Production 3.6" stack, an "Experimental tidyverse" stack, and a "Legacy CRAN 2020" stack on the same machine. | Feature | Description | |---------|-------------| | Multiple sandboxes | Isolated library trees managed independently. | | Transparent switching | switchTo("sandbox_name") changes the .libPaths() without restarting R. | | Manifest-based | Record exact package versions + sources (CRAN, GitHub, Bioc). | | Install from manifest | Recreate an environment anywhere ( install_packages(manifest) ). | | No sudo/root | Fully user-level; all packages installed to user-defined paths. | | Integration with GRANBase | Can create local CRAN-like repositories for controlled builds. | 3. Installation & Basic Usage # Install from CRAN (stable) install.packages("switchr") Or development version remotes::install_github("gmcmacran/switchr") Create a new sandbox switchr::makeSandbox("project_xyz") Activate it switchr::switchTo("project_xyz") Install packages (they go into the sandbox) install.packages("dplyr") BiocManager::install("DESeq2") Later, switch back to global/default switchr::switchTo("default") View all sandboxes switchr::listSandboxes() 4. Strengths (What Works Well) ✅ True isolation Switchr does not just change libPaths – it maintains completely independent library/ directories, including compiled bytecode. No cross-sandbox leakage. ✅ R version agnosticism You can maintain a sandbox built under R 3.6 and another under R 4.2. Switching sandboxes is safe even between minor R versions (though compiled code may need reinstallation if the R ABI changes). ✅ Reproducibility via manifests manifest <- switchr::writeManifest() # manifest is a data.frame with Package, Version, Repository, Sha (for GitHub) You can commit this manifest to Git, then on another machine:

Rating: 4.3/5 Best for: R developers, bioinformaticians, data scientists managing multiple R versions or library configurations. GitHub: gmcmacran/switchr 1. Overview & Core Philosophy Switchr (originally part of the SwitchBox ecosystem) is an R package designed to solve a chronic problem in R development: dependency hell and version isolation . switchr

switchr::install_packages(manifest) This is a lightweight alternative to renv or conda-lock . Because everything lives under ~/R/sandboxes/ , you never accidentally install.packages() into the system library or a production environment. 5. Weaknesses & Pain Points ❌ Stale maintenance As of 2024-2025, Switchr has low commit activity . The last significant updates were ~2019-2021. It still works with modern R (4.3/4.4), but some edge cases with Bioconductor 3.18+ or GitHub rate limiting may appear. ❌ No dependency locking by default Unlike renv (which creates a strict renv.lock with exact hashes), Switchr's manifest records versions but not recursive dependencies. A package update in a dependency can still break your sandbox if you rebuild from manifest without freezing CRAN. ❌ Poor Windows support While it runs on Windows, path handling can be brittle. Long paths, spaces in user names, or antivirus interference with symlinks cause frequent issues. Switchr is most stable on Linux/macOS . ❌ Learning curve for advanced features Concepts like Sandbox classes (ReferenceClass-based), pkgType control, and GRAN integration are powerful but under-documented. The vignettes cover basics but not debugging sandbox corruption. ❌ Conflicts with RStudio's "Projects" If you use RStudio’s .Rproj + renv, Switchr’s switchTo() may override RStudio’s automatic libPath, leading to confusion. Workaround: disable renv autoloading. 6. Comparison: Switchr vs Alternatives | Tool | Isolation | Lock file | R version mgmt | Active dev | Learning curve | |------|-----------|-----------|----------------|------------|----------------| | Switchr | ✅ Full | ⚠️ Partial (no recursive lock) | ❌ No (uses system R) | Low | Medium | | renv | ✅ Full | ✅ Strong ( renv.lock ) | ❌ No | High (RStudio) | Low-Medium | | conda | ✅ Full | ✅ environment.yml | ✅ Yes (via r-base ) | High | High | | packrat (deprecated) | ✅ Full | ✅ Weak | ❌ No | None | Medium | | checkpoint | ❌ (date-frozen CRAN only) | ❌ | ❌ No | Low | Low | Unlike Python’s virtualenv or conda , R lacks