What problem does it solve?
This Skill helps R developers implement robust error handling in packages, enabling consistent, user-friendly error reporting and reliable failure handling.
Core Features & Use Cases
- Formatted conditions: Use cli_abort(), cli_warn(), and cli_inform() to craft informative error and status messages.
- Error context: Attach contextual information with caller_env() and caller_arg() so end users see meaningful call traces.
- Input validation: Provide reusable checkers that validate arguments and report precise function and parameter names.
- Error chaining: Use try_fetch() to wrap operations and chain contextual errors without losing the original cause.
- Testing: Validate error behaviour with testthat snapshots to ensure snapshots reflect produced messages.
Quick Start
Load the rlang package in your package development workflow and replace base error calls with cli_abort/cli_warn/cli_inform. For example, enforce argument types with a helper that uses caller_arg() to display the correct parameter name, and wrap risky operations with try_fetch() to preserve context.