A collection of Python utilities ported from the R ecosystem.
The ruru.base module provides core utilities:
match_arg: A Python equivalent of R'smatch.argfunction for verifying function arguments against a set of valid options. Recommended usage:
from ruru.base import match_arg
user_choice = "apple"
available_choices = ["Apple", "Banana", "Cherry"]
# Normalize user input before passing it to match_arg.
# Which transformation to use depends on the style of available_choices:
# - .title() if choices look like "Apple"
# - .upper() if choices look like "APPLE"
# - .lower() if choices look like "apple"
user_choice = match_arg(user_choice.title(), available_choices)pmatch: A Python equivalent of R'spmatchfunction for finding partial substring matches against a set of reference strings.
Inspired by the R base package.
The ruru.config module gives an easy way to manage of configuration settings in Python applications via YAML files.
Recommended usage:
from importlib.resources import files
from ruru import config
config_path = files("<mypkg>.cli").joinpath("config.yml")
config_dict = config.get(file = config_path)Inspired by the R config package.
The ruru.cli module provides utilities for enhanced command-line interface output, including colored text, formatted headings, alert messages, and bullet-point lists.
Recommended usage:
from ruru import cli
cli.h1("Heading")
cli.alert("This is an alert message")Inspired by the R cli package.
