Back to Skills

manage-renv-dependencies

pjt222
Updated 2 days ago
6 views
17
2
17
View on GitHub
Othergeneral

About

This skill helps developers manage R package dependencies using renv for reproducible environments. It handles initialization, snapshot/restore workflows, troubleshooting common issues, and CI/CD integration. Use it when setting up new R projects, restoring environments on different machines, or integrating renv into automated pipelines.

Quick Install

Claude Code

Recommended
Primary
npx skills add pjt222/agent-almanac -a claude-code
Plugin CommandAlternative
/plugin add https://github.com/pjt222/agent-almanac
Git CloneAlternative
git clone https://github.com/pjt222/agent-almanac.git ~/.claude/skills/manage-renv-dependencies

Copy and paste this command in Claude Code to install this skill

Documentation


name: manage-renv-dependencies description: > renvを使用してRパッケージの依存関係を再現可能な環境で管理する。 初期化、スナップショット/リストアワークフロー、一般的な問題のトラブルシューティング、 CI/CD統合を網羅。新規Rプロジェクトへの依存関係管理の初期化、パッケージの 追加・更新、新しいマシンへの環境復元、リストア失敗のトラブルシューティング、 またはCI/CDパイプラインとのrenv統合時に使用する。 locale: ja source_locale: en source_commit: 6f65f316 translator: claude-opus-4-6 translation_date: 2026-03-16 license: MIT allowed-tools: Read Write Edit Bash Grep Glob metadata: author: Philipp Thoss version: "1.0" domain: r-packages complexity: intermediate language: R tags: r, renv, dependencies, reproducibility, lockfile

renv依存関係の管理

renvを使用して再現可能なRパッケージ環境をセットアップして保守する。

使用タイミング

  • 新規RプロジェクトへのIの依存関係管理の初期化
  • パッケージの依存関係の追加または更新
  • 新しいマシンへのプロジェクト環境の復元
  • renvのリストア失敗のトラブルシューティング
  • CI/CDパイプラインとのrenv統合

入力

  • 必須: Rプロジェクトディレクトリ
  • 任意: 既存のrenv.lockファイル(リストア用)
  • 任意: プライベートパッケージ用のGitHub PAT

手順

ステップ1: renvの初期化

renv::init()

これにより以下が作成される:

  • renv/ディレクトリ(ライブラリ、設定、アクティベーションスクリプト)
  • renv.lock(依存関係のスナップショット)
  • .Rprofileがrenvを読み込み時にアクティベートするよう更新される

期待結果: プロジェクトローカルライブラリが作成される。renv/ディレクトリとrenv.lockが存在する。.Rprofileがアクティベーションスクリプトで更新される。

失敗時: ハングする場合はネットワーク接続を確認する。特定のパッケージで失敗する場合は、そのパッケージをinstall.packages()で手動インストールしてからrenv::init()を再実行する。

ステップ2: 依存関係の追加

通常通りパッケージをインストールする:

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

状態を記録するためにスナップショットを作成する:

renv::snapshot()

期待結果: renv.lockが新しいパッケージとそのバージョンで更新される。renv::status()が同期外れのパッケージがないことを示す。

失敗時: renv::snapshot()がバリデーションエラーを報告する場合はrenv::dependencies()を実行して実際に使用されているパッケージを確認し、次にrenv::snapshot(force = TRUE)でバリデーションをバイパスする。

ステップ3: 別のマシンへの復元

renv::restore()

期待結果: renv.lockの正確なバージョンですべてのパッケージがインストールされる。

失敗時: 一般的な問題:GitHubパッケージの失敗(.RenvironGITHUB_PATを設定)、システム依存関係の欠如(Linuxでapt-getを使用してインストール)、大きなパッケージのタイムアウト(リストア前にoptions(timeout = 600)を設定)、またはバイナリが利用不可(renvがソースからコンパイル;ビルドツールがインストールされているか確認)。

ステップ4: 依存関係の更新

# 特定のパッケージを更新
renv::update("dplyr")

# すべてのパッケージを更新
renv::update()

# 更新後にスナップショットを作成
renv::snapshot()

期待結果: 対象パッケージが最新の互換バージョンに更新される。renv.lockがスナップショット後に新しいバージョンを反映する。

失敗時: renv::update()が特定のパッケージで失敗する場合はrenv::install("package@version")で直接インストールしてからスナップショットを作成する。

ステップ5: ステータスの確認

renv::status()

期待結果: 「問題なし」または同期外れのパッケージの明確なリストとアクション可能なガイダンス。

失敗時: ステータスが使用されているが記録されていないパッケージを報告する場合はrenv::snapshot()を実行する。記録されているがインストールされていないパッケージがある場合はrenv::restore()を実行する。

ステップ6: 条件付きアクティベーション用の.Rprofile設定

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

これによりrenvがインストールされていない場合(CI環境、共同作業者)でもプロジェクトが動作する。

期待結果: プロジェクトディレクトリで開始するとRセッションが自動的にrenvをアクティベートする。renvがインストールされていないセッションもエラーなく起動する。

失敗時: .Rprofileがエラーを引き起こす場合、file.exists()ガードが存在することを確認する。source("renv/activate.R")を条件なしで呼び出してはならない。

ステップ7: Git設定

これらのファイルをトラックする:

renv.lock           # 常にコミット
renv/activate.R     # 常にコミット
renv/settings.json  # 常にコミット
.Rprofile           # コミット(renvアクティベーションを含む)

これらは無視する(renvの.gitignoreに既に含まれる):

renv/library/       # マシン固有
renv/staging/       # 一時的
renv/cache/         # マシン固有のキャッシュ

期待結果: renv.lockrenv/activate.Rrenv/settings.jsonがGitでトラックされる。マシン固有のディレクトリ(renv/library/renv/cache/)が無視される。

失敗時: renv/library/が誤ってコミットされた場合はgit rm -r --cached renv/library/で削除し、.gitignoreに追加する。

ステップ8: CI/CD統合

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が条件付きでrenvをアクティベートする
  • CI/CDが依存関係解決にrenv.lockを使用する

よくある落とし穴

  • 間違ったディレクトリでrenv::init()を実行: 最初にgetwd()を確認する
  • renvとシステムライブラリの混在: renv::init()後はプロジェクトライブラリのみを使用する
  • スナップショットを忘れる: パッケージのインストール後は常にrenv::snapshot()を実行する
  • --vanillaフラグ: Rscript --vanilla.Rprofileをスキップするため、renvはアクティベートされない
  • 差分の大きなロックファイル: 正常 — renv.lockは差分可能なJSONとして設計されている
  • Bioconductorパッケージ: renv::install("bioc::PackageName")を使用してBiocManagerが設定されていることを確認する

関連スキル

  • create-r-package - renv初期化を含む
  • setup-github-actions-ci - renvとのCI統合
  • submit-to-cran - CRANパッケージの依存関係管理

GitHub Repository

pjt222/agent-almanac
Path: i18n/ja/skills/manage-renv-dependencies
0
agentsagentskillsai-assisted-developmentclaude-codeskillsteams

Related Skills

llamaguard

Other

LlamaGuard is Meta's 7-8B parameter model for moderating LLM inputs and outputs across six safety categories like violence and hate speech. It offers 94-95% accuracy and can be deployed using vLLM, Hugging Face, or Amazon SageMaker. Use this skill to easily integrate content filtering and safety guardrails into your AI applications.

View skill

cost-optimization

Other

This Claude Skill helps developers optimize cloud costs through resource rightsizing, tagging strategies, and spending analysis. It provides a framework for reducing cloud expenses and implementing cost governance across AWS, Azure, and GCP. Use it when you need to analyze infrastructure costs, right-size resources, or meet budget constraints.

View skill

quantizing-models-bitsandbytes

Other

This skill quantizes LLMs to 8-bit or 4-bit precision using bitsandbytes, achieving 50-75% memory reduction with minimal accuracy loss. It's ideal for running larger models on limited GPU memory or accelerating inference, supporting formats like INT8, NF4, and FP4. The skill integrates with HuggingFace Transformers and enables QLoRA training and 8-bit optimizers.

View skill

dispatching-parallel-agents

Other

This Claude Skill dispatches multiple agents to investigate and fix 3+ independent problems concurrently. It is designed for scenarios involving unrelated failures that can be resolved without shared state or dependencies. The core capability is parallel problem-solving, assigning one agent per independent problem domain to maximize efficiency.

View skill