-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
enhancementNew feature or requestNew feature or requestproviderRuntime provider implementationRuntime provider implementation
Description
Add R runtime provider to dtvem for managing R versions.
Overview
Implement an R provider that allows users to install, manage, and switch between R versions using dtvem. R is widely used in data science, statistics, and academic research where reproducibility is critical.
Why R Needs Version Management
- Research Reproducibility: Published papers must be reproducible with exact R version
- Package Compatibility: R packages often break between R versions
- Legacy Analysis: Need to run old analysis scripts with original R version
- Production Environments: Match development R version to production servers
- Academic Requirements: Thesis/dissertation code must work years later
- CRAN Packages: Over 19,000 packages with version-specific dependencies
Implementation Checklist
- Create
src/runtimes/r/provider.go - Implement all 19
Providerinterface methods - Add
init()function for auto-registration:runtime.Register(NewProvider()) - Import in
src/main.go:_ "github.com/CodingWithCalvin/dtvem/src/runtimes/r" - Update
schemas/runtimes.schema.jsonto add "r" to runtime enum - Implement
Shims()method to return:["R", "Rscript"] - Implement
ShouldReshimAfter()(likely false - no global executable installs) - Add detection logic for existing R installations (system, RVM)
- Implement download/installation logic from official sources
- Ensure cross-platform support (Windows, macOS, Linux)
- Add tests using provider contract harness (
internal/runtime/provider_test_harness.go) - Update documentation with R examples
Version Sources
- CRAN: https://cran.r-project.org/
- CRAN Mirrors: https://cran.r-project.org/mirrors.html
- R for Windows: https://cran.r-project.org/bin/windows/base/
- R for macOS: https://cran.r-project.org/bin/macosx/
- R Source: https://cran.r-project.org/src/base/
Download Sources by Platform
Windows
- Installers: https://cran.r-project.org/bin/windows/base/
- Format:
R-{version}-win.exe(e.g.,R-4.3.2-win.exe) - Need to extract or install silently
- Base R only (Rtools separate for package compilation)
macOS
- Installers: https://cran.r-project.org/bin/macosx/
- Format:
R-{version}.pkgorR-{version}-arm64.pkg - Intel (x86_64) and Apple Silicon (arm64) builds available
- Need to extract .pkg without system installation
Linux
- Source Tarballs: https://cran.r-project.org/src/base/R-{major}/
- Format:
R-{version}.tar.gz - Must compile from source (dependencies required)
- Or use prebuilt binaries from distributions
Migration Sources
Detect and migrate from:
- System installations:
- Windows:
C:\Program Files\R\R-{version}\ - macOS:
/Library/Frameworks/R.framework/Versions/{version}/ - Linux:
/usr/bin/R,/usr/local/bin/R
- Windows:
- RVM (R Version Manager): If exists
- RStudio: May bundle R versions
Package Libraries
R packages are typically installed per major.minor version:
- User Library:
~/R/{platform}-library/{major}.{minor}/ - Site Library: System-wide package location
- Decision: Each R version should have its own library
- Location:
~/.dtvem/versions/r/{version}/library/ - Set
R_LIBS_USERenvironment variable
- Location:
Shims to Create
R- Main R interpreter (case-sensitive!)Rscript- Command-line R script execution
Automatic Reshim Detection
Implement ShouldReshimAfter():
- Returns
false- R doesn't install global executables - R packages are libraries, not executables
- Exception: Some packages install command-line tools, but rare
Cross-Platform Considerations
Windows
- Installer Extraction: May need to extract from .exe installer
- Rtools: Separate download for compiling packages (optional)
- PATH: Add
bin/,bin/x64/to PATH - Registry: System R writes to registry, dtvem versions shouldn't
macOS
- Framework Bundle: R.framework structure
/Resources/bin/R/Resources/bin/Rscript
- Architecture: Intel vs Apple Silicon
- R 4.1+ has arm64 builds for M1/M2
- Dependency: May need Xcode Command Line Tools for package compilation
Linux
- Compilation: Must compile from source or use distro packages
- Dependencies: Many (gcc, gfortran, libreadline, libcurl, etc.)
- Package Compilation: Need development headers for system libraries
Version Format
- R uses semantic-like versioning:
4.3.2,4.2.1,3.6.3 - Format:
{major}.{minor}.{patch} - Major version changes are rare (last was 3.x → 4.0 in 2020)
- Minor versions:
4.0,4.1,4.2,4.3,4.4(annual releases)
R Package Compatibility
- Packages compiled for R 4.3.x often work on R 4.3.y (same minor)
- Packages must be recompiled for major.minor changes (4.2 → 4.3)
- renv: R's equivalent to Python's virtualenv
- Per-project package libraries
- Works alongside dtvem's version management
Testing Requirements
- Use provider contract harness in
runtimes/r/provider_test.go - Test all 19 interface methods
- Test version detection from system installations
- Test installation on all platforms
- Test shim creation and execution
- Test R_LIBS_USER environment variable setup
Special Considerations
RStudio Integration
- RStudio detects R installations automatically
- Should work with dtvem-managed R versions
- RStudio preferences allow selecting R version
Package Installation
- Packages installed with
install.packages() - Stored in version-specific library directories
- Binary packages (Windows/macOS) vs source packages (Linux)
Bioconductor
- Separate repository for bioinformatics packages
- Version tied to R version (Bioconductor 3.18 → R 4.3)
CRAN Task Views
- Curated package collections for specific domains
- Not managed by dtvem
Environment Variables
R_HOME: Points to R installation directoryR_LIBS_USER: User package library locationR_LIBS_SITE: Site-wide package library- dtvem should set these per version
Configuration Files
.Rprofile: R startup configuration (often in project directory).Renviron: Environment variables (often in project directory)~/.Rprofile: User-level startup (shared across versions)
Integration with Data Science Workflows
- Jupyter: R kernel (IRkernel) for Jupyter notebooks
- RMarkdown: Literate programming documents
- Shiny: Web applications built with R
- Posit (RStudio) Products: Workbench, Connect, Package Manager
renv Integration
R's renv package provides project-level package management:
- Similar to Python's
venvor Node'snode_modules renv::init()creates project-specific library- Works alongside dtvem (dtvem manages R version, renv manages packages)
Academic/Research Context
- Reproducibility: Core requirement in research
- Long-term Archival: Code must run years after publication
- Thesis/Dissertation: PhD students need code to work for defense
- Collaborators: Different lab members may use different R versions
References
- Provider interface:
src/internal/runtime/provider.go - Example implementations:
src/runtimes/node/,src/runtimes/python/ - Adding providers guide:
.claude/CLAUDE.md - R Project: https://www.r-project.org/
- CRAN: https://cran.r-project.org/
- renv: https://rstudio.github.io/renv/
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requestproviderRuntime provider implementationRuntime provider implementation