r-code
Write R code following tidyverse style guide. Use when writing R functions, scripts, or any R code.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Write R code following tidyverse style guide. Use when writing R functions, scripts, or any R code.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
Access R package documentation and learn about packages. Use when exploring packages, finding function help, or understanding package capabilities.
Explore and inspect R data frames, objects, and environments interactively. Use when the user wants to understand data structure, preview data, or investigate R objects.
Develop R packages following best practices. Use when creating packages, writing package functions, documentation, or tests.
rlang metaprogramming patterns for data-masking, injection operators, and dynamic dots. Use when writing functions that use tidy evaluation.
基于 SOC 职业分类
| name | r-code |
| description | Write R code following tidyverse style guide. Use when writing R functions, scripts, or any R code. |
Write R code following tidyverse conventions.
c, mean, T, F)# Good
day_one
calculate_mean()
# Bad
DayOne
calculateMean()
dayOne
Use <-, not =:
# Good
x <- 5
# Bad
x = 5
x[, 1]x <- y + z::, $, @, [, [[, ^, :() with if, for, while{{ }} has inner spaces# Good
mean(x, na.rm = TRUE)
df$column
x <- 1:10
sqrt(x^2 + y^2)
if (debug) {
show(x)
}
data |>
dplyr::group_by({{ by }}) |>
dplyr::summarise(max = max({{ var }}))
# Bad
mean(x,na.rm=TRUE)
df $ column
x <- 1 : 10
if(debug){show(x)}
Only use return() for early returns
# Good
find_abs <- function(x) {
if (x > 0) {
return(x)
}
x * -1
}
add_two <- function(x, y) {
x + y
}
# Bad
add_two <- function(x, y) {
return(x + y)
}
Lambda syntax \(x) for short anonymous functions
# Good
purrr::map(xs, \(x) x + 1)
# Bad
purrr::map(xs, ~ .x + 1)
Multi-line definitions - single indent style
long_function_name <- function(
a = "a long argument",
b = "another argument"
) {
# body
}
Side-effect functions return first argument invisibly
print.my_class <- function(x, ...) {
cat("Value: ", x$value, "\n", sep = "")
invisible(x)
}
&& and || in if conditions, never & or |ifelse on same line as }{} block# Good
if (y < 0) {
rlang::abort("y must be positive")
}
if (x > 10) {
x * 2
} else {
x * 3
}
# Bad
if (y < 0) stop("y must be positive")
|> (R 4.1+)# Good
df |>
dplyr::filter(x > 0) |>
dplyr::mutate(y = x * 2) |>
dplyr::summarise(mean_y = mean(y))
# Bad
df |> dplyr::filter(x > 0) |> dplyr::mutate(y = x * 2)
Always use explicit namespaces for non-base R functions:
# Good
dplyr::filter(df, x > 0)
rlang::abort("Error message")
purrr::map(xs, \(x) x + 1)
# Bad
filter(df, x > 0)
abort("Error message")
" for strings, not 'TRUE/FALSE, never T/Fseq_along(x) not 1:length(x)# Good
"Text"
TRUE
seq_along(x)
# Bad
'Text'
T
1:length(x)
# (hash + space)# Objects like data frames are treated as leaves
x <- purrr::map_if(x, rlang::is_bare_list, recurse)
= for assignmentT and F instead of TRUE and FALSE1:length(x) instead of seq_along(x)sapply() (use vapply() or purrr::map_*())if conditionsWhen the btw MCP server is available, prefer btw_tool_run_r over Bash + Rscript -e "...":
# Use btw_tool_run_r for multi-step work
# Call 1: load and inspect
df <- readr::read_csv("data.csv")
str(df)
# Call 2: objects from call 1 are still available
df |> dplyr::count(category, sort = TRUE)
Reserve Bash + Rscript only for one-off commands where session state doesn't matter.