executing-plans
executing-plans
Use when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is available
manage-renv-dependenciesManage R package dependencies using renv for reproducible environments. Covers initialization, snapshot/restore workflow, troubleshooting common issues, and CI/CD integration. Use when initializing dependency management for a new R project, adding or updating packages, restoring an environment on a new machine, troubleshooting restore failures, or integrati…
Independent GitHub snapshot · Automated classification · Original documentation governs
以 renv 設並維可重 R 包環境。
renv.lock(恢用)renv::init()
此造:
renv/ 目(庫、設、啟腳本)renv.lock(依快照).Rprofile 載時啟 renv得:項本地庫造。renv/ 目與 renv.lock 在。.Rprofile 更附啟腳本。
敗:掛→查網連。特包敗→先手動 install.packages() 裝後重運 renv::init()。
常裝包:
install.packages("dplyr")
renv::install("github-user/private-pkg")
後快照記態:
renv::snapshot()
得:renv.lock 更附新包與版。renv::status() 示無失同包。
敗:renv::snapshot() 報驗誤→運 renv::dependencies() 察哪包實用,後 renv::snapshot(force = TRUE) 繞驗。
renv::restore()
得:諸包裝於 renv.lock 之確版。
敗:常問題:GitHub 包敗(於 .Renviron 設 GITHUB_PAT);缺系統依(Linux 以 apt-get 裝);大包超時(恢前設 options(timeout = 600));無二進(renv 由源編;確備工具裝)。
# Update a specific package
renv::update("dplyr")
# Update all packages
renv::update()
# Snapshot after updates
renv::snapshot()
得:目包更至新兼容版。renv.lock 快照後反新版。
敗:renv::update() 為特包敗→試以 renv::install("package@version") 直裝後快照。
renv::status()
得:「No issues found」或失同包之明列附可行指。
敗:態報用而未記之包→運 renv::snapshot()。已記而未裝之包→運 renv::restore()。
.Rprofile 為條件啟if (file.exists("renv/activate.R")) {
source("renv/activate.R")
}
此確即 renv 未裝(CI 環、協作者)項亦行。
得:R 會話於項目中啟時自啟 renv。無 renv 之會話仍無誤啟。
敗:.Rprofile 致誤→確 file.exists() 守存。永勿無條件呼 source("renv/activate.R")。
追此文件:
renv.lock # Always commit
renv/activate.R # Always commit
renv/settings.json # Always commit
.Rprofile # Commit (contains renv activation)
忽此(已於 renv 之 .gitignore):
renv/library/ # Machine-specific
renv/staging/ # Temporary
renv/cache/ # Machine-specific cache
得:renv.lock、renv/activate.R、renv/settings.json 由 Git 追。機特目(renv/library/、renv/cache/)忽。
敗:renv/library/ 誤提→以 git rm -r --cached renv/library/ 除並加 .gitignore。
GitHub Actions 用 renv 緩動:
- uses: r-lib/actions/setup-renv@v2
此自由 renv.lock 附緩恢。
得:CI 管線由 renv.lock 恢包附緩啟。後運因緩包更速。
敗:CI 恢敗→查 renv.lock 提且新。私 GitHub 包→確 GITHUB_PAT 設為庫秘。
renv::status() 報無問題renv.lock 提於版控renv::restore() 於淨檢出上行.Rprofile 條件啟 renvrenv.lock 為依解renv::init():必先驗 getwd()renv::init() 後僅用項庫renv::snapshot()--vanilla 旗:Rscript --vanilla 略 .Rprofile → renv 不啟renv.lock 設為可 diff JSONrenv::install("bioc::PackageName") 並確 BiocManager 配create-r-package - 含 renv 啟setup-github-actions-ci - 與 renv 之 CI 合submit-to-cran - CRAN 包之依管