返回技能列表

manage-renv-dependencies

pjt222
更新于 2 days ago
5 次查看
17
2
17
在 GitHub 上查看
其他aiapiautomation

关于

This skill helps developers manage R package dependencies using renv to create reproducible environments. It covers initializing projects, snapshotting/restoring dependencies, troubleshooting issues, and CI/CD integration. Use it when setting up new R projects, adding/updating packages, or restoring environments across different machines.

快速安装

Claude Code

推荐
主要方式
npx skills add pjt222/agent-almanac -a claude-code
插件命令备选方式
/plugin add https://github.com/pjt222/agent-almanac
Git 克隆备选方式
git clone https://github.com/pjt222/agent-almanac.git ~/.claude/skills/manage-renv-dependencies

在 Claude Code 中复制并粘贴此命令以安装该技能

技能文档

Manage renv Dependencies

Set up and maintain reproducible R package environments using renv.

When Use

  • Initializing dependency management for new R project
  • Adding or updating package dependencies
  • Restoring project environment on new machine
  • Troubleshooting renv restore failures
  • Integrating renv with CI/CD pipelines

Inputs

  • Required: R project directory
  • Optional: Existing renv.lock file (for restore)
  • Optional: GitHub PAT for private packages

Steps

Step 1: Initialize renv

renv::init()

This creates:

  • renv/ directory (library, settings, activation script)
  • renv.lock (dependency snapshot)
  • Updates .Rprofile to activate renv on load

Got: Project-local library created. renv/ directory and renv.lock present. .Rprofile updated with activation script.

If fail: Hangs? Check network connectivity. Fails on specific package? Install that package manually first with install.packages() then rerun renv::init().

Step 2: Add Dependencies

Install packages as usual:

install.packages("dplyr")
renv::install("github-user/private-pkg")

Then snapshot to record state:

renv::snapshot()

Got: renv.lock updated with new packages and versions. renv::status() shows no out-of-sync packages.

If fail: renv::snapshot() reports validation errors? Run renv::dependencies() to check which packages actually used, then renv::snapshot(force = TRUE) to bypass validation.

Step 3: Restore on Another Machine

renv::restore()

Got: All packages installed at exact versions in renv.lock.

If fail: Common issues: GitHub packages fail (set GITHUB_PAT in .Renviron), system dependencies missing (install with apt-get on Linux), timeouts on large packages (set options(timeout = 600) before restore), binaries not available (renv compiles from source. Ensure build tools installed).

Step 4: Update Dependencies

# Update a specific package
renv::update("dplyr")

# Update all packages
renv::update()

# Snapshot after updates
renv::snapshot()

Got: Target packages updated to latest compatible versions. renv.lock reflects new versions after snapshot.

If fail: renv::update() fails for specific package? Try installing directly with renv::install("package@version") then snapshot.

Step 5: Check Status

renv::status()

Got: "No issues found" or clear list of out-of-sync packages with actionable guidance.

If fail: Status reports packages used but not recorded? Run renv::snapshot(). Packages recorded but not installed? Run renv::restore().

Step 6: Configure .Rprofile for Conditional Activation

if (file.exists("renv/activate.R")) {
  source("renv/activate.R")
}

Ensures project works even if renv isn't installed (CI environments, collaborators).

Got: R sessions activate renv automatically when starting in project directory. Sessions without renv installed still start without errors.

If fail: .Rprofile causes errors? Ensure file.exists() guard present. Never call source("renv/activate.R") unconditionally.

Step 7: Git Configuration

Track these files:

renv.lock           # Always commit
renv/activate.R     # Always commit
renv/settings.json  # Always commit
.Rprofile           # Commit (contains renv activation)

Ignore these (already in renv's .gitignore):

renv/library/       # Machine-specific
renv/staging/       # Temporary
renv/cache/         # Machine-specific cache

Got: renv.lock, renv/activate.R, renv/settings.json tracked by Git. Machine-specific directories (renv/library/, renv/cache/) ignored.

If fail: renv/library/ accidentally gets committed? Remove with git rm -r --cached renv/library/ and add to .gitignore.

Step 8: CI/CD Integration

In GitHub Actions, use renv cache action:

- uses: r-lib/actions/setup-renv@v2

Automatically restores from renv.lock with caching.

Got: CI pipeline restores packages from renv.lock with caching enabled. Subsequent runs faster due to cached packages.

If fail: CI restore fails? Check renv.lock is committed and up to date. For private GitHub packages, ensure GITHUB_PAT set as repository secret.

Checks

  • renv::status() reports no issues
  • renv.lock committed to version control
  • renv::restore() works on clean checkout
  • .Rprofile conditionally activates renv
  • CI/CD uses renv.lock for dependency resolution

Pitfalls

  • Running renv::init() in wrong directory: Always verify getwd() first
  • Mixing renv and system library: After renv::init(), only use project library
  • Forgetting to snapshot: After installing packages, always run renv::snapshot()
  • --vanilla flag: Rscript --vanilla skips .Rprofile, so renv won't activate
  • Large lock files in diffs: Normal — renv.lock designed to be diffable JSON
  • Bioconductor packages: Use renv::install("bioc::PackageName") and ensure BiocManager configured

See Also

  • create-r-package - includes renv initialization
  • setup-github-actions-ci - CI integration with renv
  • submit-to-cran - dependency management for CRAN packages

GitHub 仓库

pjt222/agent-almanac
路径: i18n/caveman/skills/manage-renv-dependencies
0
agentsagentskillsai-assisted-developmentclaude-codeskillsteams

相关推荐技能

llamaguard

其他

LlamaGuard是Meta推出的7-8B参数内容审核模型,专门用于过滤LLM的输入和输出内容。它能检测六大安全风险类别(暴力/仇恨、性内容、武器、违禁品、自残、犯罪计划),准确率达94-95%。开发者可通过HuggingFace、vLLM或Sagemaker快速部署,并能与NeMo Guardrails集成实现自动化安全防护。

查看技能

cost-optimization

其他

这个Claude Skill帮助开发者优化云成本,通过资源调整、标记策略和预留实例来降低AWS、Azure和GCP的开支。它适用于减少云支出、分析基础设施成本或实施成本治理策略的场景。关键功能包括提供成本可视化、资源规模调整指导和定价模型优化建议。

查看技能

quantizing-models-bitsandbytes

其他

这个Skill使用bitsandbytes库量化大语言模型,能在GPU内存有限时通过8位或4位量化减少50-75%内存占用,同时保持精度损失最小。它支持INT8、NF4、FP4等多种量化格式,可与HuggingFace Transformers无缝集成,适用于需要部署更大模型或加速推理的场景。还提供QLoRA训练和8位优化器支持,让开发者能轻松实现高效模型压缩。

查看技能

dispatching-parallel-agents

其他

该Skill用于并行处理3个以上无依赖关系的独立故障,可为每个问题域分派专属Claude代理同时执行调查修复。它通过并发处理多个独立问题显著提升故障排查效率,特别适用于测试文件、子系统等无共享状态的场景。

查看技能