r-development
Modern R development practices emphasizing tidyverse patterns (dplyr 1.1 and later, native pipe, join_by, .by grouping), rlang metaprogramming, performance optimization, and package development. Use when Claude needs to write R code, create R packages, optimize R performance, or provide R programming guidance.
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o r-development.zip https://jpskill.com/download/17993.zip && unzip -o r-development.zip && rm r-development.zip
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/17993.zip -OutFile "$d\r-development.zip"; Expand-Archive "$d\r-development.zip" -DestinationPath $d -Force; ri "$d\r-development.zip"
完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。
💾 手動でダウンロードしたい(コマンドが難しい人向け)
- 1. 下の青いボタンを押して
r-development.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
r-developmentフォルダができる - 3. そのフォルダを
C:\Users\あなたの名前\.claude\skills\(Win)または~/.claude/skills/(Mac)へ移動 - 4. Claude Code を再起動
⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。
🎯 このSkillでできること
下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。
📦 インストール方法 (3ステップ)
- 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
- 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
- 3. 展開してできたフォルダを、ホームフォルダの
.claude/skills/に置く- · macOS / Linux:
~/.claude/skills/ - · Windows:
%USERPROFILE%\.claude\skills\
- · macOS / Linux:
Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。
詳しい使い方ガイドを見る →- 最終更新
- 2026-05-18
- 取得日時
- 2026-05-18
- 同梱ファイル
- 5
📖 Skill本文(日本語訳)
※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。
R開発
このスキルでは、tidyverse、パフォーマンス最適化、プロフェッショナルなパッケージ開発における最新のベストプラクティスを重視し、現代的なR開発のための包括的なガイダンスを提供します。
コア原則
- 最新のtidyverseパターンを使用する - dplyr 1.1+の機能、ネイティブパイプ、および現在のAPIを優先します。
- 最適化の前にプロファイルする - profvisとbenchを使用して、実際のボトルネックを特定します。
- 最初に読みやすいコードを書く - 最適化は必要な場合にのみ、プロファイル後に実行します。
- tidyverseスタイルガイドに従う - 一貫した命名、スペーシング、および構造。
現代的なTidyverseの必須事項
ネイティブパイプ (%>% ではなく |>)
常にmagrittrの%>%の代わりにネイティブパイプ|>を使用してください(R 4.1+):
# 現代的
data |>
filter(year >= 2020) |>
summarise(mean_value = mean(value))
# レガシーパイプは避ける
data %>% filter(year >= 2020)
Join構文 (dplyr 1.1+)
すべてのjoinにjoin_by()を使用します。
# 等価性による現代的なjoin構文
transactions |>
inner_join(companies, by = join_by(company == id))
# 不等価join
transactions |>
inner_join(companies, join_by(company == id, year >= since))
# ローリングjoin(最も近い一致)
transactions |>
inner_join(companies, join_by(company == id, closest(year >= since)))
一致の動作を制御します。
# 1:1の一致を期待する
inner_join(x, y, by = join_by(id), multiple = "error")
# すべての行が一致することを確認する
inner_join(x, y, by = join_by(id), unmatched = "error")
.by を使用した操作ごとのグルーピング
group_by() |> ... |> ungroup()の代わりに.byを使用します。
# 現代的なアプローチ(常にungroupedを返す)
data |>
summarise(mean_value = mean(value), .by = category)
# 複数のグルーピング変数
data |>
summarise(total = sum(revenue), .by = c(company, year))
列操作
最新の列選択および変換関数を使用します。
# データマスキングコンテキストでの列選択のためのpick()
data |>
summarise(
n_x_cols = ncol(pick(starts_with("x"))),
n_y_cols = ncol(pick(starts_with("y")))
)
# 複数の列に関数を適用するためのacross()
data |>
summarise(across(where(is.numeric), mean, .names = "mean_{.col}"), .by = group)
# グループごとに複数行の結果を得るためのreframe()
data |>
reframe(quantiles = quantile(x, c(0.25, 0.5, 0.75)), .by = group)
rlangメタプログラミング
包括的なrlangパターンについては、references/rlang-patterns.mdを参照してください。
簡単なリファレンス
{{}}- データマスキング関数に引数を転送します!!- 単一の式または値を挿入します!!!- リストから複数の引数を挿入します.data[[]]- 名前(文字ベクトル)で列にアクセスしますpick()- データマスキング関数内で列を選択します
抱擁(embracing)を使用した関数の例:
my_summary <- function(data, group_var, summary_var) {
data |>
summarise(mean_val = mean({{ summary_var }}), .by = {{ group_var }})
}
パフォーマンス最適化
詳細なパフォーマンスガイダンスについては、references/performance.mdを参照してください。
主要な戦略
- 最初にプロファイルする:
profvis::profvis()とbench::mark()を使用します - 操作をベクトル化する: ベクトル化された代替手段が存在する場合は、ループを避けます
- dtplyrを使用する: 大規模なデータ操作の場合(data.tableバックエンドによる遅延評価)
- 並列処理: 並列化可能な作業には
furrr::future_map()を使用します - メモリ効率: 事前割り当て、適切なデータ型を使用します
簡単な例:
# コードのプロファイル
profvis::profvis({
result <- data |>
complex_operation() |>
another_operation()
})
# 代替手段のベンチマーク
bench::mark(
approach_1 = method1(data),
approach_2 = method2(data),
check = FALSE
)
パッケージ開発
完全なパッケージ開発ガイダンスについては、references/package-development.mdを参照してください。
簡単なガイドライン
API設計:
- 操作ごとのグルーピングには
.byパラメータを使用します - 列引数には
{{}}を使用します - 一貫してtibbleを返します
- ユーザー向けの関数入力を徹底的に検証します
依存関係:
- 大きな機能向上のために依存関係を追加します
- コアのtidyverseパッケージ(dplyr、purrr、stringr、tidyr)は通常含める価値があります
- 広く使用されるパッケージの依存関係を最小限に抑えます
テスト:
- 個々の関数のユニットテスト
- ワークフローの統合テスト
- エッジケースとエラー条件のテスト
ドキュメント:
- エクスポートされたすべての関数をドキュメント化します
- 使用例を提供します
- 自明でないパラメータの相互作用を説明します
一般的な移行パターン
Base R → Tidyverse
# データ操作
subset(data, condition) → filter(data, condition)
data[order(data$x), ] → arrange(data, x)
aggregate(x ~ y, data, mean) → summarise(data, mean(x), .by = y)
# 関数型プログラミング
sapply(x, f) → map(x, f) # 型安定
lapply(x, f) → map(x, f)
# 文字列
grepl("pattern", text) → str_detect(text, "pattern")
gsub("old", "new", text) → str_replace_all(text, "old", "new")
古い → 新しい Tidyverse
# パイプ
%>% → |>
# グルーピング
group_by() |> ... |> ungroup() → summarise(..., .by = x)
# Join
by = c("a" = "b") → by = join_by(a == b)
# リシェイプ
gather()/spread() → pivot_longer()/pivot_wider()
追加リソース
- rlangパターン: 包括的なデータマスキングとメタプログラミングのガイダンスについては、references/rlang-patterns.mdを参照してください。
- パフォーマンス最適化: プロファイリング、ベンチマーク、および最適化戦略については、references/performance.mdを参照してください。
- パッケージ開発: 完全なパッケージ作成ガイダンスについては、references/package-development.mdを参照してください。
- オブジェクトシステム: S3、S4、S7、R6、およびvctrsのガイダンスについては、references/object-systems.mdを参照してください。
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開
R Development
This skill provides comprehensive guidance for modern R development, emphasizing current best practices with tidyverse, performance optimization, and professional package development.
Core Principles
- Use modern tidyverse patterns - Prioritize dplyr 1.1+ features, native pipe, and current APIs
- Profile before optimizing - Use profvis and bench to identify real bottlenecks
- Write readable code first - Optimize only when necessary and after profiling
- Follow tidyverse style guide - Consistent naming, spacing, and structure
Modern Tidyverse Essentials
Native Pipe (|> not %>%)
Always use native pipe |> instead of magrittr %>% (R 4.1+):
# Modern
data |>
filter(year >= 2020) |>
summarise(mean_value = mean(value))
# Avoid legacy pipe
data %>% filter(year >= 2020)
Join Syntax (dplyr 1.1+)
Use join_by() for all joins:
# Modern join syntax with equality
transactions |>
inner_join(companies, by = join_by(company == id))
# Inequality joins
transactions |>
inner_join(companies, join_by(company == id, year >= since))
# Rolling joins (closest match)
transactions |>
inner_join(companies, join_by(company == id, closest(year >= since)))
Control match behavior:
# Expect 1:1 matches
inner_join(x, y, by = join_by(id), multiple = "error")
# Ensure all rows match
inner_join(x, y, by = join_by(id), unmatched = "error")
Per-Operation Grouping with .by
Use .by instead of group_by() |> ... |> ungroup():
# Modern approach (always returns ungrouped)
data |>
summarise(mean_value = mean(value), .by = category)
# Multiple grouping variables
data |>
summarise(total = sum(revenue), .by = c(company, year))
Column Operations
Use modern column selection and transformation functions:
# pick() for column selection in data-masking contexts
data |>
summarise(
n_x_cols = ncol(pick(starts_with("x"))),
n_y_cols = ncol(pick(starts_with("y")))
)
# across() for applying functions to multiple columns
data |>
summarise(across(where(is.numeric), mean, .names = "mean_{.col}"), .by = group)
# reframe() for multi-row results per group
data |>
reframe(quantiles = quantile(x, c(0.25, 0.5, 0.75)), .by = group)
rlang Metaprogramming
For comprehensive rlang patterns, see references/rlang-patterns.md.
Quick Reference
{{}}- Forward function arguments to data-masking functions!!- Inject single expressions or values!!!- Inject multiple arguments from a list.data[[]]- Access columns by name (character vectors)pick()- Select columns inside data-masking functions
Example function with embracing:
my_summary <- function(data, group_var, summary_var) {
data |>
summarise(mean_val = mean({{ summary_var }}), .by = {{ group_var }})
}
Performance Optimization
For detailed performance guidance, see references/performance.md.
Key Strategies
- Profile first: Use
profvis::profvis()andbench::mark() - Vectorize operations: Avoid loops when vectorized alternatives exist
- Use dtplyr: For large data operations (lazy evaluation with data.table backend)
- Parallel processing: Use
furrr::future_map()for parallelizable work - Memory efficiency: Pre-allocate, use appropriate data types
Quick example:
# Profile code
profvis::profvis({
result <- data |>
complex_operation() |>
another_operation()
})
# Benchmark alternatives
bench::mark(
approach_1 = method1(data),
approach_2 = method2(data),
check = FALSE
)
Package Development
For complete package development guidance, see references/package-development.md.
Quick Guidelines
API Design:
- Use
.byparameter for per-operation grouping - Use
{{}}for column arguments - Return tibbles consistently
- Validate user-facing function inputs thoroughly
Dependencies:
- Add dependencies for significant functionality gains
- Core tidyverse packages usually worth including: dplyr, purrr, stringr, tidyr
- Minimize dependencies for widely-used packages
Testing:
- Unit tests for individual functions
- Integration tests for workflows
- Test edge cases and error conditions
Documentation:
- Document all exported functions
- Provide usage examples
- Explain non-obvious parameter interactions
Common Migration Patterns
Base R → Tidyverse
# Data manipulation
subset(data, condition) → filter(data, condition)
data[order(data$x), ] → arrange(data, x)
aggregate(x ~ y, data, mean) → summarise(data, mean(x), .by = y)
# Functional programming
sapply(x, f) → map(x, f) # type-stable
lapply(x, f) → map(x, f)
# Strings
grepl("pattern", text) → str_detect(text, "pattern")
gsub("old", "new", text) → str_replace_all(text, "old", "new")
Old → New Tidyverse
# Pipes
%>% → |>
# Grouping
group_by() |> ... |> ungroup() → summarise(..., .by = x)
# Joins
by = c("a" = "b") → by = join_by(a == b)
# Reshaping
gather()/spread() → pivot_longer()/pivot_wider()
Additional Resources
- rlang patterns: See references/rlang-patterns.md for comprehensive data-masking and metaprogramming guidance
- Performance optimization: See references/performance.md for profiling, benchmarking, and optimization strategies
- Package development: See references/package-development.md for complete package creation guidance
- Object systems: See references/object-systems.md for S3, S4, S7, R6, and vctrs guidance
同梱ファイル
※ ZIPに含まれるファイル一覧。`SKILL.md` 本体に加え、参考資料・サンプル・スクリプトが入っている場合があります。
- 📄 SKILL.md (6,250 bytes)
- 📎 references/object-systems.md (7,077 bytes)
- 📎 references/package-development.md (8,553 bytes)
- 📎 references/performance.md (8,179 bytes)
- 📎 references/rlang-patterns.md (6,416 bytes)