# SmartCane Project - Package Management ## Quick Start ### For New Team Members 1. Open R/RStudio 2. Set working directory to the project root: `setwd("path/to/smartcane")` 3. Run: `source("r_app/package_manager.R")` 4. Type `y` when prompted 5. Wait for completion ✅ ### For Existing Team Members (After Git Pull) Same steps as above - the script will check for updates automatically. ## What This Script Does 1. **Initializes renv** - Creates isolated package environment 2. **Checks package versions** - Compares installed vs required 3. **Installs/Updates packages** - Only if needed 4. **Creates lockfile** - `renv.lock` for exact reproducibility 5. **Generates reports** - Console output + `package_manager.log` ## Key Features - ✅ **Minimum version requirements** (allows patch updates) - ✅ **Critical package locking** (tmap v4 for new syntax) - ✅ **Automatic installation** of missing packages - ✅ **Console + Log output** for debugging - ✅ **Cross-platform compatibility** ## Required Packages & Versions | Package | Min Version | Purpose | |---------|-------------|---------| | tmap | 4.0.0 | **CRITICAL** - New syntax used | | tidyverse | 2.0.0 | Data manipulation | | sf | 1.0.0 | Spatial data | | terra | 1.7.0 | Raster processing | | rmarkdown | 2.21.0 | Report generation | ## Workflow ### Development Workflow ``` 1. 👨‍💻 Developer: Make changes → run package_manager.R → test → commit + push 2. 👥 Teammate: Pull → run package_manager.R → test 3. 🚀 Production: Pull → run package_manager.R → deploy ``` ### Files Created - `renv.lock` - Exact package versions (commit this!) - `package_manager.log` - Installation log (don't commit) - `renv/` folder - Package cache (don't commit) ## Troubleshooting ### "Package failed to install" - Check internet connection - Update R to latest version - Install system dependencies (varies by OS) ### "Version conflicts" - Delete `renv/` folder - Run script again for clean install ### "renv not working" - Install manually: `install.packages("renv")` - Restart R session - Run script again ## Team Guidelines 1. **Always run** `package_manager.R` after pulling changes 2. **Commit** `renv.lock` to git (not `renv/` folder) 3. **Don't modify** package versions in scripts - use this manager 4. **Report issues** in the log file to team ## Advanced Usage ### Restore from lockfile only: ```r renv::restore() ``` ### Add new package requirement: 1. Edit `REQUIRED_PACKAGES` in `package_manager.R` 2. Run the script 3. Commit updated `renv.lock` ### Check status without changes: ```r source("r_app/package_manager.R") # Then just read the log or run generate_package_report() ```