feat: add btw CLI via Rapp for command-line access to R tools#176
feat: add btw CLI via Rapp for command-line access to R tools#176
Conversation
Implement a command-line interface for btw using Rapp (R CLI framework).
The CLI wraps the four tool groups as two-level subcommands:
- btw docs {help,vignette,news} — R package documentation
- btw pkg {document,check,test,load,coverage} — package development
- btw info {platform,packages} — R environment info
- btw cran {search,info} — CRAN package registry
Includes:
- exec/btw: Main Rapp script with nested switch() dispatch
- install_btw_cli(): Convenience installer that checks all dependencies
- Rapp (>= 0.3.0) added to Suggests
Implements _dev/agents/cli/design.md
- Quote short flag annotations to prevent YAML boolean coercion (bare `n` was parsed as `false`) - Fall back to listing available vignettes when intro vignette not found, instead of erroring - Catch warnings from vignette() (signals warning, not error, when vignette not found)
Allow `btw docs help dplyr::mutate` as an alternative to `btw docs help mutate --package dplyr`, mirroring standard R notation. The :: form takes priority; if --package is also provided, a warning is emitted and the flag is ignored.
Change switch defaults from NULL (required positional) to "" (optional) so that running `btw`, `btw docs`, etc. without a subcommand prints scoped help text instead of erroring. Uses Rapp:::print_app_help() via commandArgs(TRUE)[1] to render the same output as --help.
- pkgdown requires all exported topics in the reference index - Tests use processx::run() which must be declared in Suggests
- Add has_value() helper to check for both NA and empty string
sentinels, replacing bare is.na() checks throughout
- Add defensive S7 type check in btw_output() before property
extraction, with a clear error for unexpected types
- Switch optional flag defaults from NA_character_ to "" for
cleaner help text (avoids [default: "NA"] display)
- Flip btw docs help fallback: try topic first, fall back to
package listing (more intuitive for common usage)
- Add {package} syntax for explicitly requesting package listing
- Update tests to match new "" defaults and new fallback behavior
- Document {package} syntax for explicit package topic listing
- Document pkg::topic scoped help syntax
- Fix --path <dir> on btw pkg test (was missing <dir> placeholder)
Add JSON output support for `btw info platform`, `btw info packages`, and `btw info packages --check`. The --json flag is a group-level option that applies to all info subcommands. Adds btw_json_output() helper using jsonlite::toJSON for structured output suitable for piping to jq or other tools.
Add JSON output support for `btw cran search` and `btw cran info`. The --json flag is a group-level option that applies to all cran subcommands. Handles serialization of pkgsearch S3 classes (numeric_version, cran_package) that jsonlite doesn't natively support.
Add JSON output support for `btw pkg coverage`. The --json flag is a subcommand-level option (only coverage produces structured data in the pkg group). Returns the coverage data frame as JSON, with filename and coverage percentage columns for package-level, or line-level details when --file is specified.
|
this is great, I just saw couple of days ago that new Rapp was published and now I see that you've added this to btw. Have you done some benchmarking to compare token consumption between CLI version and MCP version of these tools? |
Thanks! I don't have any benchmarking, but I the CLI version will definitely use less tokens. The skill that comes with the CLI teaches the model how to use The other is that if you're using btw tools via MCP you're likely including all of the tool definitions in your system prompt, which is also included even if you aren't doing anything with R in your session. With the CLI, however, less than 100 tokens are used for the skill description, so your system prompt overhead is much lower. |
Summary
Adds a
btwCLI that wraps the package's tool groups — docs, pkg, info, and cran — so that both humans and LLMs can invoke them from the command line via Rapp.Key pieces:
exec/btw.R— The Rapp CLI script with two-level command dispatch (btw <group> <command> [args] [flags]). Supports TTY-aware output (colored for terminals, plain markdown when piped).R/cli.R—install_btw_cli()installer function that verifies all CLI dependencies are present before installing, plus an interactive prompt to install ther-btw-cliskill.inst/cli-skill/r-btw-cli/SKILL.md— Claude Code skill file documenting CLI usage for AI agents.tests/testthat/test-cli.Rcovering argument parsing, help text, topic/package lookup semantics, JSON output, and error cases.CLI commands implemented:
btw docs help,btw docs vignette,btw docs newsbtw pkg document|check|test|load|coveragebtw info platform|packagesbtw cran search|infoNotable behaviors
Topic-first help lookup —
btw docs help <name>tries to resolve as a help topic first, falling back to a package listing. Usebtw docs help {<pkg>}to explicitly request a package listing, orbtw docs help <pkg>::<topic>for scoped lookup.--jsonflag — Structured JSON output for commands with tabular/list data, suitable for piping tojq:Verification