types-check

Validate R function inputs using rlang check functions with clear error messages.

343|67|Updated Apr 22, 2017
One-click install
npx skills add https://github.com/tidymodels/rsample --skill types-check-tidymodels
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: types-check
Source: https://github.com/tidymodels/rsample/tree/main/.claude/skills/tidy-argument-checking
Command: npx skills add https://github.com/tidymodels/rsample --skill types-check-tidymodels

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires rlang.

What problem does it solve? R functions often fail with cryptic errors when users pass invalid arguments. This Skill guides you through tidyverse-style input validation using rlang's standalone check_* functions, producing clear, actionable error messages at function entry points. ## Core Features & Use Cases - Scalar and Vector Checkers: Use check_string(), check_number_whole(), check_bool(), check_logical(), check_character(), and check_data_frame() to validate argument types with options like min, max, allow_na, and allow_null. - Argument Helpers: Apply arg_match() for enumerated choices, check_exclusive() for mutually exclusive arguments, and check_required() for mandatory parameters. - Custom Check Functions: Build your own check_* wrappers that correctly propagate arg and call context, or create new validators with stop_input_type(). - Use Case: When writing an exported R package function like create_report(title, n_rows), validate inputs at the entry point so internal helpers can trust the data without redundant checks. ## Quick Start Add tidyverse-style input validation to my exported R function using rlang check functions.

Frequently Asked Questions about types-check

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I validate function arguments in R?▼

Use rlang's standalone check_* functions like check_string(), check_number_whole(), and check_bool() at the start of exported functions. They produce clear error messages and support options like min, max, allow_na, and allow_null.

What is the difference between check_string and check_name in rlang?▼

check_string() validates a single string and allows empty strings by default, while check_name() requires a single non-empty string. Use check_name() for variable names or symbols passed as strings.

Should I validate inputs in internal R helper functions?▼

No, validate only at entry points like exported functions or functions consuming external data. Once validated at the boundary, internal helpers can trust the data, similar to gradual typing in TypeScript.

Why do my custom check function errors show the wrong function name?▼

Your wrapper is not propagating caller context. Add arg = caller_arg(x) and call = caller_env() to your wrapper's signature and pass them through to the underlying check_* function so errors point to the entry point.

How do I allow NULL as a valid argument value in R validation?▼

Set allow_null = TRUE in scalar checkers like check_number_decimal(timeout, allow_null = TRUE). This treats NULL as a valid no-value state, matching the tidyverse preference for NULL defaults over missing() defaults.