$ show klmr/box
box is an R package that provides a modern, modular module system for organizing R code into hierarchical, composable, and reusable modules. It replaces the traditional `library` and `require` functions with a declarative, explicit import syntax (`box::use`) that supports selective name attachment, aliasing, and scoped imports. The system handles both packages and local R scripts as first-class modules, supports S3 method registration, cyclic imports, interactive help, and module lifecycle hooks (`.on_load`, `.on_unload`). The architecture is built on custom environment manipulation, a PEG-like specification parser, a caching layer for loaded modules, and a small C extension for performance-critical operations. The codebase is well-structured, extensively tested, and demonstrates advanced use of R's environment and S3 dispatch mechanisms.
The LLM identified 3 files worth highlighting for reuse:
Provides a versatile string interpolation function `fmt` that embeds R expressions in strings with optional format modifiers (quoting, numeric formatting). Also defines a `chr` S3 generic for converting values to strings, with methods for calls, names, and other unevaluated expressions. This module is self-contained, has no internal dependencies beyond base R, and can be extracted for use in any R project requiring advanced text formatting.
Implements a generic help formatting and display system for module documentation. Defines an S3 class hierarchy for output formats (text, HTML) with methods `compile_help`, `patch_topic_name`, and `display_help_file`. Uses `tools::parse_Rd` to convert roxygen2-generated Rd to the desired format, then displays it via `file.show` or a local HTTP server. This is a clean, extensible pattern for building custom help viewers in R.
Implements a consistent error reporting system with `throw`, `rethrow`, `expect`, and `rethrow_on_error` functions. It creates structured error conditions with custom subclasses, stores the call stack for traceback, and provides a mechanism to override the traceback with cleaner call sequences when rethrowing errors from helper functions. Useful for any R package that needs informative, structured error messages.