| Title: | Core Utilities for the 'rtemis' Ecosystem |
|---|---|
| Description: | Utilities used across packages of the 'rtemis' ecosystem. Includes the msg() messaging system and the fmt() formatting system. Provides a library of 'S7' properties, test_* functions that return logical values, check_* functions that throw informative errors, and clean_* functions that return validated and coerced values. This code began as part of the 'rtemis' package (<doi:10.32614/CRAN.package.rtemis>). |
| Authors: | E.D. Gennatas [aut, cre, cph] (ORCID: <https://orcid.org/0000-0001-9280-3609>) |
| Maintainer: | E.D. Gennatas <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 0.2.0 |
| Built: | 2026-05-27 20:10:46 UTC |
| Source: | https://github.com/rtemis-org/rtemis.core |
Core Utilities for rtemis R Packages
Maintainer: E.D. Gennatas [email protected] (ORCID) [copyright holder]
Authors:
E.D. Gennatas [email protected] (ORCID) [copyright holder]
Useful links:
Report bugs at https://github.com/rtemis-org/rtemis.core/issues
Abbreviate object class name
abbreviate_class(x, n = 4L)abbreviate_class(x, n = 4L)
x |
Object. |
n |
Integer: Minimum abbreviation length. |
Character: Abbreviated class wrapped in angle brackets.
EDG
abbreviate_class(iris) abbreviate_class(iris, n = 3)abbreviate_class(iris) abbreviate_class(iris, n = 3)
Signals a condition AND optionally writes a styled event line to the operator console. The two channels carry complementary information so nothing is duplicated:
abort(..., class = NULL, parent = NULL, verbosity = NULL, package = NULL)abort(..., class = NULL, parent = NULL, verbosity = NULL, package = NULL)
... |
Message components, concatenated with no separator. |
class |
Character vector: Additional condition classes (prepended
to the base |
parent |
Condition or NULL: Wrapped parent condition. Its message is
echoed to the console (when verbosity allows) and stored on the
signalled condition as |
verbosity |
Integer or NULL: Overrides |
package |
Character or NULL: Package name for verbosity override. |
Console echo (when verbosity allows): the most-specific condition
class plus the caller bracket - a structured "what failed, where"
line. Falls back to "rtemis_error" when class = NULL so the line
is always namespace-tagged and recognizable as ours.
Condition $message: the corrective human-readable text passed
via .... Plain text with all ANSI escapes stripped, so it is safe
to serialize into JSON, HTML, or any other ANSI-unaware sink (e.g.
browser-side error display), and is what conditionMessage() /
R's default error printer / tryCatch(error = ...) handlers see.
Use class to add wire-protocol-specific condition classes that callers
can catch via tryCatch(). The base classes "rtemis_error", "error",
and "condition" are always added.
The condition also carries $trace - a pairlist of sys.calls()
captured at the abort site, with abort()'s own frame trimmed. Unlike
base R's traceback() (which only sees .Traceback, populated only
when an error reaches the top-level uncaught), $trace survives
tryCatch() and travels with the condition - so server-side handlers
can ship the stack to a browser-side debug pane, or callers can call
format_trace() to print it.
Does not return - always signals a condition via stop().
EDG
## Not run: abort("Could not parse ", "hyperparameters", ".", class = "rtemislive_invalid_params") ## End(Not run)## Not run: abort("Could not parse ", "hyperparameters", ".", class = "rtemislive_invalid_params") ## End(Not run)
Convert ANSI 256 color code to HEX
ansi256_to_hex(code)ansi256_to_hex(code)
code |
Integer: ANSI 256 color code (0-255). |
Character: HEX color string.
EDG
ansi256_to_hex(1)ansi256_to_hex(1)
A fmt() convenience wrapper for making text bold.
bold(text, output_type = c("ansi", "html", "plain"))bold(text, output_type = c("ansi", "html", "plain"))
text |
Character: Text to make bold |
output_type |
Character: Output type ("ansi", "html", "plain") |
Character: Formatted text with bold styling
EDG
message(bold("This is bold!"))message(bold("This is bold!"))
Returns a new_property() for a double scalar constrained to a given interval.
Useful for bounds not covered by the pre-built properties.
bounded_double_property( lower = -Inf, upper = Inf, lower_open = FALSE, upper_open = FALSE, nullable = FALSE )bounded_double_property( lower = -Inf, upper = Inf, lower_open = FALSE, upper_open = FALSE, nullable = FALSE )
lower |
Numeric scalar. Lower bound. Default |
upper |
Numeric scalar. Upper bound. Default |
lower_open |
Logical scalar. If |
upper_open |
Logical scalar. If |
nullable |
Logical scalar. If |
An S7 property object.
EDG
# Learning rate in (0, 1] lr_prop <- bounded_double_property(0, 1, lower_open = TRUE)# Learning rate in (0, 1] lr_prop <- bounded_double_property(0, 1, lower_open = TRUE)
S7 property accepting a single non-NA, non-empty (after trimming whitespace) string.
character_scalarcharacter_scalar
An S7 property object.
EDG
Check character
check_character(x, allow_null = TRUE, arg_name = deparse(substitute(x)))check_character(x, allow_null = TRUE, arg_name = deparse(substitute(x)))
x |
Vector to check. |
allow_null |
Logical: If TRUE, NULL values are allowed and return early. |
arg_name |
Character: Name of the variable for error messages. |
Called for side effects. Throws an error if check fails.
EDG
check_character("papaya") # Throws error: try(check_character(42L))check_character("papaya") # Throws error: try(check_character(42L))
Check character scalar
check_character_scalar(x, arg_name = deparse(substitute(x)))check_character_scalar(x, arg_name = deparse(substitute(x)))
x |
Character: Value to check. Must be a single non-NA, non-empty string. |
arg_name |
Character: Argument name to use in error messages. |
Called for side effects. Throws an error if checks fail.
EDG
check_character_scalar("hello") # Throw error: try(check_character_scalar("")) try(check_character_scalar(NA_character_)) try(check_character_scalar(c("a", "b")))check_character_scalar("hello") # Throw error: try(check_character_scalar("")) try(check_character_scalar(NA_character_)) try(check_character_scalar(c("a", "b")))
Check data.table
check_data.table(x, arg_name = deparse(substitute(x)))check_data.table(x, arg_name = deparse(substitute(x)))
x |
Object to check. |
arg_name |
Character: Name of the variable for error messages. |
Called for side effects. Throws an error if input is not a data.table, returns x invisibly otherwise.
EDG
check_data.table(data.table::as.data.table(iris)) # Throws error: try(check_data.table(iris))check_data.table(data.table::as.data.table(iris)) # Throws error: try(check_data.table(iris))
Checks if dependencies can be loaded; names missing dependencies if not.
check_dependencies(..., verbosity = 0L)check_dependencies(..., verbosity = 0L)
... |
List or vector of strings defining namespaces to be checked |
verbosity |
Integer: Verbosity level. Note: An error will always printed if dependencies are missing. Setting this to FALSE stops it from printing "Dependencies check passed". |
Called for side effects. Aborts and prints list of missing dependencies, if any.
EDG
check_dependencies("base") # Throws error: try(check_dependencies("zlorbglorb"))check_dependencies("base") # Throws error: try(check_dependencies("zlorbglorb"))
Check double scalar
check_double_scalar(x, arg_name = deparse(substitute(x)))check_double_scalar(x, arg_name = deparse(substitute(x)))
x |
Numeric: Value to check. Must be a single non-NA number (integer inputs are accepted). |
arg_name |
Character: Argument name to use in error messages. |
Called for side effects. Throws an error if checks fail.
EDG
check_double_scalar(3.14) check_double_scalar(1L) # Throw error: try(check_double_scalar(NA_real_)) try(check_double_scalar(c(1.0, 2.0)))check_double_scalar(3.14) check_double_scalar(1L) # Throw error: try(check_double_scalar(NA_real_)) try(check_double_scalar(c(1.0, 2.0)))
Checks if a value is in a set of allowed values, and throws an error if not.
check_enum(x, allowed_values, arg_name = deparse(substitute(x)))check_enum(x, allowed_values, arg_name = deparse(substitute(x)))
x |
Value to check. |
allowed_values |
Vector of allowed values. |
arg_name |
Character: Name of the variable for error messages. |
Called for side effects. Throws an error if x is not in allowed_values, returns x invisibly otherwise.
EDG
check_enum("apple", c("apple", "banana", "cherry")) # Throws error: try(check_enum("granola", c("croissant", "bagel", "scramble")))check_enum("apple", c("apple", "banana", "cherry")) # Throws error: try(check_enum("granola", c("croissant", "bagel", "scramble")))
Check float -1 <= x <= 1
check_float_neg1_1(x, allow_null = TRUE, arg_name = deparse(substitute(x)))check_float_neg1_1(x, allow_null = TRUE, arg_name = deparse(substitute(x)))
x |
Numeric vector. |
allow_null |
Logical: If TRUE, NULL values are allowed and return early. |
arg_name |
Character: Name of the variable for error messages. |
Called for side effects. Throws an error if checks fail.
EDG
check_float_neg1_1(c(-1, 0, 1)) # Throws error: try(check_float_neg1_1(c(-1.5, 0, 1.5)))check_float_neg1_1(c(-1, 0, 1)) # Throws error: try(check_float_neg1_1(c(-1.5, 0, 1.5)))
Check float between 0 and 1, exclusive
check_float01exc(x, allow_null = TRUE, arg_name = deparse(substitute(x)))check_float01exc(x, allow_null = TRUE, arg_name = deparse(substitute(x)))
x |
Numeric vector. |
allow_null |
Logical: If TRUE, NULL values are allowed and return early. |
arg_name |
Character: Name of the variable for error messages. |
Called for side effects. Throws an error if checks fail.
EDG
check_float01exc(c(0.2, 0.7)) # Throws error: try(check_float01exc(c(0, 0.5, 1)))check_float01exc(c(0.2, 0.7)) # Throws error: try(check_float01exc(c(0, 0.5, 1)))
Check float between 0 and 1, inclusive
check_float01inc(x, allow_null = TRUE, arg_name = deparse(substitute(x)))check_float01inc(x, allow_null = TRUE, arg_name = deparse(substitute(x)))
x |
Numeric vector. |
allow_null |
Logical: If TRUE, NULL values are allowed and return early. |
arg_name |
Character: Name of the variable for error messages. |
Called for side effects. Throws an error if checks fail.
EDG
check_float01inc(0.5)check_float01inc(0.5)
Checks if an input is a numeric vector containing non-negative
(>= 0) values and no NAs. It is designed to validate function arguments.
check_float0pos(x, allow_null = TRUE, arg_name = deparse(substitute(x)))check_float0pos(x, allow_null = TRUE, arg_name = deparse(substitute(x)))
x |
Numeric vector. |
allow_null |
Logical: If TRUE, NULL values are allowed and return early. |
arg_name |
Character: Name of the variable for error messages. |
Called for side effects. Throws an error if checks fail.
EDG
check_float0pos(c(0, 0.5, 1)) # Allows integers since they are numeric and can be coerced to double without loss of information check_float0pos(c(0L, 1L)) # Throws error: try(check_float0pos(c(-1.5, 0, 1.5)))check_float0pos(c(0, 0.5, 1)) # Allows integers since they are numeric and can be coerced to double without loss of information check_float0pos(c(0L, 1L)) # Throws error: try(check_float0pos(c(-1.5, 0, 1.5)))
Check positive float
check_floatpos(x, allow_null = TRUE, arg_name = deparse(substitute(x)))check_floatpos(x, allow_null = TRUE, arg_name = deparse(substitute(x)))
x |
Numeric vector. |
allow_null |
Logical: If TRUE, NULL values are allowed and return early. |
arg_name |
Character: Name of the variable for error messages. |
Checking with is.numeric() allows integer inputs as well, which should be ok since it is
unlikely the function that consumes this will enforce double type only, but instead is most
likely to allow implicit coercion from integer to numeric.
Called for side effects. Throws an error if checks fail.
EDG
check_floatpos(c(0.5, 1.5)) # Allows integers since they are numeric and can be coerced to double without loss of information check_floatpos(c(1L, 3L)) # Throws error: try(check_floatpos(c(-1.5, 0.5, 1.5)))check_floatpos(c(0.5, 1.5)) # Allows integers since they are numeric and can be coerced to double without loss of information check_floatpos(c(1L, 3L)) # Throws error: try(check_floatpos(c(-1.5, 0.5, 1.5)))
Check float in (0, 1]
check_floatpos1(x, allow_null = TRUE, arg_name = deparse(substitute(x)))check_floatpos1(x, allow_null = TRUE, arg_name = deparse(substitute(x)))
x |
Numeric vector. |
allow_null |
Logical: If TRUE, NULL values are allowed and return early. |
arg_name |
Character: Name of the variable for error messages. |
Called for side effects. Throws an error if checks fail.
EDG
check_floatpos1(c(0.5, 1)) # Throw error: try(check_floatpos1(c(0, 0.7))) try(check_floatpos1(c(0.5, 1.5)))check_floatpos1(c(0.5, 1)) # Throw error: try(check_floatpos1(c(0, 0.7))) try(check_floatpos1(c(0.5, 1.5)))
Check class of object
check_inherits(x, cl, allow_null = TRUE, arg_name = deparse(substitute(x)))check_inherits(x, cl, allow_null = TRUE, arg_name = deparse(substitute(x)))
x |
Object to check. |
cl |
Character: class to check against. |
allow_null |
Logical: If TRUE, NULL values are allowed and return early. |
arg_name |
Character: Name of the variable for error messages. |
Called for side effects. Throws an error if checks fail.
EDG
check_inherits("papaya", "character") # These will throw errors: try(check_inherits(c(1, 2.5, 3.2), "integer")) try(check_inherits(iris, "list"))check_inherits("papaya", "character") # These will throw errors: try(check_inherits(c(1, 2.5, 3.2), "integer")) try(check_inherits(iris, "list"))
Check integer scalar
check_integer_scalar(x, arg_name = deparse(substitute(x)))check_integer_scalar(x, arg_name = deparse(substitute(x)))
x |
Numeric: Value to check. Must be a single non-NA whole number. |
arg_name |
Character: Argument name to use in error messages. |
Accepts any single numeric value that is a whole number. Integer-typed inputs (1L) and
double-typed whole numbers (1, 100) are both accepted for user convenience.
Called for side effects. Throws an error if checks fail.
EDG
check_integer_scalar(5L) check_integer_scalar(100) # Throw error: try(check_integer_scalar(1.5)) try(check_integer_scalar(NA_integer_))check_integer_scalar(5L) check_integer_scalar(100) # Throw error: try(check_integer_scalar(1.5)) try(check_integer_scalar(NA_integer_))
Check logical
check_logical(x, allow_null = TRUE, arg_name = deparse(substitute(x)))check_logical(x, allow_null = TRUE, arg_name = deparse(substitute(x)))
x |
Vector to check. |
allow_null |
Logical: If TRUE, NULL values are allowed and return early. |
arg_name |
Character: Name of the variable for error messages. |
Called for side effects. Throws an error if checks fail.
EDG
check_logical(c(TRUE, FALSE)) # Throws error: try(check_logical(c(0, 1)))check_logical(c(TRUE, FALSE)) # Throws error: try(check_logical(c(0, 1)))
Check logical scalar
check_logical_scalar(x, arg_name = deparse(substitute(x)))check_logical_scalar(x, arg_name = deparse(substitute(x)))
x |
Logical: Value to check. Must be a single non-NA |
arg_name |
Character: Argument name to use in error messages. |
Called for side effects. Throws an error if checks fail.
EDG
check_logical_scalar(TRUE) check_logical_scalar(FALSE) # Throw error: try(check_logical_scalar(NA)) try(check_logical_scalar(1L)) try(check_logical_scalar(c(TRUE, FALSE)))check_logical_scalar(TRUE) check_logical_scalar(FALSE) # Throw error: try(check_logical_scalar(NA)) try(check_logical_scalar(1L)) try(check_logical_scalar(c(TRUE, FALSE)))
Check non-negative double scalar
check_nonneg_double_scalar(x, arg_name = deparse(substitute(x)))check_nonneg_double_scalar(x, arg_name = deparse(substitute(x)))
x |
Numeric: Value to check. Must be a single finite number greater than or equal to zero. |
arg_name |
Character: Argument name to use in error messages. |
Called for side effects. Throws an error if checks fail.
EDG
check_nonneg_double_scalar(0) check_nonneg_double_scalar(5) # Throw error: try(check_nonneg_double_scalar(-0.001)) try(check_nonneg_double_scalar(Inf))check_nonneg_double_scalar(0) check_nonneg_double_scalar(5) # Throw error: try(check_nonneg_double_scalar(-0.001)) try(check_nonneg_double_scalar(Inf))
Check non-negative double vector
check_nonneg_double_vector(x, arg_name = deparse(substitute(x)))check_nonneg_double_vector(x, arg_name = deparse(substitute(x)))
x |
Numeric: Value to check. Must be a non-empty vector with all elements finite, greater than or equal to zero, and no NAs. |
arg_name |
Character: Argument name to use in error messages. |
Called for side effects. Throws an error if checks fail.
EDG
check_nonneg_double_vector(c(0, 1, 2.5)) # Throw error: try(check_nonneg_double_vector(c(-1, 0, 1))) try(check_nonneg_double_vector(c(1, Inf)))check_nonneg_double_vector(c(0, 1, 2.5)) # Throw error: try(check_nonneg_double_vector(c(-1, 0, 1))) try(check_nonneg_double_vector(c(1, Inf)))
Checks that x is numeric. Uses is.numeric(), which accepts both
"double" and "integer" inputs - the right semantics for "is this a
number?". Prefer this over check_inherits(x, "numeric"), which
rejects integers because their literal class is "integer", not
"numeric" (a long-standing R/S3 quirk). This trips up wire-format
callers: jsonlite::fromJSON("1") returns an integer, and the value
would then fail inherits(., "numeric") despite being a perfectly
good number.
check_numeric(x, allow_null = TRUE, arg_name = deparse(substitute(x)))check_numeric(x, allow_null = TRUE, arg_name = deparse(substitute(x)))
x |
Vector to check. |
allow_null |
Logical: If TRUE, NULL values are allowed and return early. |
arg_name |
Character: Name of the variable for error messages. |
Called for side effects. Throws an error if checks fail.
EDG
check_numeric(1L) check_numeric(1.5) check_numeric(c(1, 2, 3)) # Throws error: try(check_numeric("1")) try(check_numeric(TRUE))check_numeric(1L) check_numeric(1.5) check_numeric(c(1, 2, 3)) # Throws error: try(check_numeric("1")) try(check_numeric(TRUE))
Check optional character scalar
check_optional_character_scalar(x, arg_name = deparse(substitute(x)))check_optional_character_scalar(x, arg_name = deparse(substitute(x)))
x |
Optional Character: Value to check. Must be |
arg_name |
Character: Argument name to use in error messages. |
Called for side effects. Throws an error if checks fail.
EDG
check_optional_character_scalar(NULL) check_optional_character_scalar("hello") # Throw error: try(check_optional_character_scalar("")) try(check_optional_character_scalar(c("a", "b")))check_optional_character_scalar(NULL) check_optional_character_scalar("hello") # Throw error: try(check_optional_character_scalar("")) try(check_optional_character_scalar(c("a", "b")))
Check optional double scalar
check_optional_double_scalar(x, arg_name = deparse(substitute(x)))check_optional_double_scalar(x, arg_name = deparse(substitute(x)))
x |
Optional Numeric: Value to check. Must be |
arg_name |
Character: Argument name to use in error messages. |
Called for side effects. Throws an error if checks fail.
EDG
check_optional_double_scalar(NULL) check_optional_double_scalar(2.5) # Throw error: try(check_optional_double_scalar(NA_real_))check_optional_double_scalar(NULL) check_optional_double_scalar(2.5) # Throw error: try(check_optional_double_scalar(NA_real_))
Check optional integer scalar
check_optional_integer_scalar(x, arg_name = deparse(substitute(x)))check_optional_integer_scalar(x, arg_name = deparse(substitute(x)))
x |
Optional Numeric: Value to check. Must be |
arg_name |
Character: Argument name to use in error messages. |
Called for side effects. Throws an error if checks fail.
EDG
check_optional_integer_scalar(NULL) check_optional_integer_scalar(10L) # Throw error: try(check_optional_integer_scalar(1.5))check_optional_integer_scalar(NULL) check_optional_integer_scalar(10L) # Throw error: try(check_optional_integer_scalar(1.5))
Check optional logical scalar
check_optional_logical_scalar(x, arg_name = deparse(substitute(x)))check_optional_logical_scalar(x, arg_name = deparse(substitute(x)))
x |
Optional Logical: Value to check. Must be |
arg_name |
Character: Argument name to use in error messages. |
Called for side effects. Throws an error if checks fail.
EDG
check_optional_logical_scalar(NULL) check_optional_logical_scalar(FALSE) # Throw error: try(check_optional_logical_scalar(NA))check_optional_logical_scalar(NULL) check_optional_logical_scalar(FALSE) # Throw error: try(check_optional_logical_scalar(NA))
Check optional non-negative double scalar
check_optional_nonneg_double_scalar(x, arg_name = deparse(substitute(x)))check_optional_nonneg_double_scalar(x, arg_name = deparse(substitute(x)))
x |
Optional Numeric: Value to check. Must be |
arg_name |
Character: Argument name to use in error messages. |
Called for side effects. Throws an error if checks fail.
EDG
check_optional_nonneg_double_scalar(NULL) check_optional_nonneg_double_scalar(0) # Throw error: try(check_optional_nonneg_double_scalar(-1))check_optional_nonneg_double_scalar(NULL) check_optional_nonneg_double_scalar(0) # Throw error: try(check_optional_nonneg_double_scalar(-1))
Check optional non-negative double vector
check_optional_nonneg_double_vector(x, arg_name = deparse(substitute(x)))check_optional_nonneg_double_vector(x, arg_name = deparse(substitute(x)))
x |
Optional Numeric: Value to check. Must be |
arg_name |
Character: Argument name to use in error messages. |
Called for side effects. Throws an error if checks fail.
EDG
check_optional_nonneg_double_vector(NULL) check_optional_nonneg_double_vector(c(0, 1, 5)) # Throw error: try(check_optional_nonneg_double_vector(c(-1, 0)))check_optional_nonneg_double_vector(NULL) check_optional_nonneg_double_vector(c(0, 1, 5)) # Throw error: try(check_optional_nonneg_double_vector(c(-1, 0)))
Check optional positive double scalar
check_optional_pos_double_scalar(x, arg_name = deparse(substitute(x)))check_optional_pos_double_scalar(x, arg_name = deparse(substitute(x)))
x |
Optional Numeric: Value to check. Must be |
arg_name |
Character: Argument name to use in error messages. |
Called for side effects. Throws an error if checks fail.
EDG
check_optional_pos_double_scalar(NULL) check_optional_pos_double_scalar(2.5) # Throw error: try(check_optional_pos_double_scalar(0))check_optional_pos_double_scalar(NULL) check_optional_pos_double_scalar(2.5) # Throw error: try(check_optional_pos_double_scalar(0))
Check optional positive double vector
check_optional_pos_double_vector(x, arg_name = deparse(substitute(x)))check_optional_pos_double_vector(x, arg_name = deparse(substitute(x)))
x |
Optional Numeric: Value to check. Must be |
arg_name |
Character: Argument name to use in error messages. |
Called for side effects. Throws an error if checks fail.
EDG
check_optional_pos_double_vector(NULL) check_optional_pos_double_vector(c(0.5, 2)) # Throw error: try(check_optional_pos_double_vector(c(0, 1)))check_optional_pos_double_vector(NULL) check_optional_pos_double_vector(c(0.5, 2)) # Throw error: try(check_optional_pos_double_vector(c(0, 1)))
Check optional positive integer scalar
check_optional_pos_integer_scalar(x, arg_name = deparse(substitute(x)))check_optional_pos_integer_scalar(x, arg_name = deparse(substitute(x)))
x |
Optional Numeric: Value to check. Must be |
arg_name |
Character: Argument name to use in error messages. |
Called for side effects. Throws an error if checks fail.
EDG
check_optional_pos_integer_scalar(NULL) check_optional_pos_integer_scalar(5L) # Throw error: try(check_optional_pos_integer_scalar(0))check_optional_pos_integer_scalar(NULL) check_optional_pos_integer_scalar(5L) # Throw error: try(check_optional_pos_integer_scalar(0))
Check optional probability scalar
check_optional_prob_scalar(x, arg_name = deparse(substitute(x)))check_optional_prob_scalar(x, arg_name = deparse(substitute(x)))
x |
Optional Numeric: Value to check. Must be |
arg_name |
Character: Argument name to use in error messages. |
Called for side effects. Throws an error if checks fail.
EDG
check_optional_prob_scalar(NULL) check_optional_prob_scalar(0.5) # Throw error: try(check_optional_prob_scalar(2.0))check_optional_prob_scalar(NULL) check_optional_prob_scalar(0.5) # Throw error: try(check_optional_prob_scalar(2.0))
Check optional probability vector
check_optional_prob_vector(x, arg_name = deparse(substitute(x)))check_optional_prob_vector(x, arg_name = deparse(substitute(x)))
x |
Optional Numeric: Value to check. Must be |
arg_name |
Character: Argument name to use in error messages. |
Called for side effects. Throws an error if checks fail.
EDG
check_optional_prob_vector(NULL) check_optional_prob_vector(c(0.2, 0.8)) # Throw error: try(check_optional_prob_vector(c(0.5, 2)))check_optional_prob_vector(NULL) check_optional_prob_vector(c(0.2, 0.8)) # Throw error: try(check_optional_prob_vector(c(0.5, 2)))
Check Optional Scalar Character
check_optional_scalar_character(x, arg_name = deparse(substitute(x)))check_optional_scalar_character(x, arg_name = deparse(substitute(x)))
x |
Optional Character: Value to check. |
arg_name |
Character: Argument name to use in error messages. |
Called for side effects.
EDG
check_optional_scalar_character(NULL, "my_arg") check_optional_scalar_character("hello", "my_arg") # Throw error: try(check_optional_scalar_character(c("hello", "world"), "my_arg")) try(check_optional_scalar_character(123, "my_arg"))check_optional_scalar_character(NULL, "my_arg") check_optional_scalar_character("hello", "my_arg") # Throw error: try(check_optional_scalar_character(c("hello", "world"), "my_arg")) try(check_optional_scalar_character(123, "my_arg"))
Check optional open-unit-interval vector
check_optional_unit_open_vector(x, arg_name = deparse(substitute(x)))check_optional_unit_open_vector(x, arg_name = deparse(substitute(x)))
x |
Optional Numeric: Value to check. Must be |
arg_name |
Character: Argument name to use in error messages. |
Called for side effects. Throws an error if checks fail.
EDG
check_optional_unit_open_vector(NULL) check_optional_unit_open_vector(c(0.1, 0.9)) # Throw error: try(check_optional_unit_open_vector(c(0, 0.5)))check_optional_unit_open_vector(NULL) check_optional_unit_open_vector(c(0.1, 0.9)) # Throw error: try(check_optional_unit_open_vector(c(0, 0.5)))
Check positive double scalar
check_pos_double_scalar(x, arg_name = deparse(substitute(x)))check_pos_double_scalar(x, arg_name = deparse(substitute(x)))
x |
Numeric: Value to check. Must be a single finite number strictly greater than zero. |
arg_name |
Character: Argument name to use in error messages. |
Called for side effects. Throws an error if checks fail.
EDG
check_pos_double_scalar(0.001) check_pos_double_scalar(100) # Throw error: try(check_pos_double_scalar(0)) try(check_pos_double_scalar(-1)) try(check_pos_double_scalar(Inf))check_pos_double_scalar(0.001) check_pos_double_scalar(100) # Throw error: try(check_pos_double_scalar(0)) try(check_pos_double_scalar(-1)) try(check_pos_double_scalar(Inf))
Check positive double vector
check_pos_double_vector(x, arg_name = deparse(substitute(x)))check_pos_double_vector(x, arg_name = deparse(substitute(x)))
x |
Numeric: Value to check. Must be a non-empty vector with all elements finite, strictly greater than zero, and no NAs. |
arg_name |
Character: Argument name to use in error messages. |
Called for side effects. Throws an error if checks fail.
EDG
check_pos_double_vector(c(0.1, 1, 10)) # Throw error: try(check_pos_double_vector(c(0, 1))) try(check_pos_double_vector(c(1, Inf)))check_pos_double_vector(c(0.1, 1, 10)) # Throw error: try(check_pos_double_vector(c(0, 1))) try(check_pos_double_vector(c(1, Inf)))
Check positive integer scalar
check_pos_integer_scalar(x, arg_name = deparse(substitute(x)))check_pos_integer_scalar(x, arg_name = deparse(substitute(x)))
x |
Numeric: Value to check. Must be a single non-NA whole number greater than zero. |
arg_name |
Character: Argument name to use in error messages. |
Accepts any single numeric value that is a whole number strictly greater than zero.
Integer-typed inputs (1L) and double-typed whole numbers (1, 100) are both accepted for
user convenience.
Called for side effects. Throws an error if checks fail.
EDG
check_pos_integer_scalar(1L) check_pos_integer_scalar(10) # Throw error: try(check_pos_integer_scalar(0)) try(check_pos_integer_scalar(-1L)) try(check_pos_integer_scalar(1.5))check_pos_integer_scalar(1L) check_pos_integer_scalar(10) # Throw error: try(check_pos_integer_scalar(0)) try(check_pos_integer_scalar(-1L)) try(check_pos_integer_scalar(1.5))
Check probability scalar
check_prob_scalar(x, arg_name = deparse(substitute(x)))check_prob_scalar(x, arg_name = deparse(substitute(x)))
x |
Numeric: Value to check. Must be a single finite number in |
arg_name |
Character: Argument name to use in error messages. |
Called for side effects. Throws an error if checks fail.
EDG
check_prob_scalar(0) check_prob_scalar(0.5) check_prob_scalar(1) # Throw error: try(check_prob_scalar(1.5)) try(check_prob_scalar(-0.1))check_prob_scalar(0) check_prob_scalar(0.5) check_prob_scalar(1) # Throw error: try(check_prob_scalar(1.5)) try(check_prob_scalar(-0.1))
Check probability vector
check_prob_vector(x, arg_name = deparse(substitute(x)))check_prob_vector(x, arg_name = deparse(substitute(x)))
x |
Numeric: Value to check. Must be a non-empty vector with all elements in |
arg_name |
Character: Argument name to use in error messages. |
Called for side effects. Throws an error if checks fail.
EDG
check_prob_vector(c(0, 0.5, 1)) # Throw error: try(check_prob_vector(c(0.5, 1.5))) try(check_prob_vector(c(0.5, NA)))check_prob_vector(c(0, 0.5, 1)) # Throw error: try(check_prob_vector(c(0.5, 1.5))) try(check_prob_vector(c(0.5, NA)))
Check Scalar Character
check_scalar_character(x, arg_name = deparse(substitute(x)))check_scalar_character(x, arg_name = deparse(substitute(x)))
x |
Character: Value to check. |
arg_name |
Character: Argument name to use in error messages. |
Called for side effects.
EDG
check_scalar_character("hello", "my_arg") # Throw error: try(check_scalar_character(c("hello", "world"), "my_arg")) try(check_scalar_character(123, "my_arg"))check_scalar_character("hello", "my_arg") # Throw error: try(check_scalar_character(c("hello", "world"), "my_arg")) try(check_scalar_character(123, "my_arg"))
Check Scalar Logical
check_scalar_logical(x, arg_name = deparse(substitute(x)))check_scalar_logical(x, arg_name = deparse(substitute(x)))
x |
Logical: Value to check. |
arg_name |
Character: Argument name to use in error messages. |
Called for side effects.
EDG
check_scalar_logical(TRUE, "my_arg") # Throw error: try(check_scalar_logical(c(TRUE, FALSE), "my_arg")) try(check_scalar_logical(NA, "my_arg"))check_scalar_logical(TRUE, "my_arg") # Throw error: try(check_scalar_logical(c(TRUE, FALSE), "my_arg")) try(check_scalar_logical(NA, "my_arg"))
Checks if object is of class data.frame, data.table, or tbl_df.
check_tabular(x)check_tabular(x)
x |
Object to check. |
Called for side effects. Throws an error if input is not tabular, returns x invisibly otherwise.
EDG
check_tabular(iris) check_tabular(data.table::as.data.table(iris)) # Throws error: try(check_tabular(matrix(1:10, ncol = 2)))check_tabular(iris) check_tabular(data.table::as.data.table(iris)) # Throws error: try(check_tabular(matrix(1:10, ncol = 2)))
Check open-unit-interval scalar
check_unit_open_scalar(x, arg_name = deparse(substitute(x)))check_unit_open_scalar(x, arg_name = deparse(substitute(x)))
x |
Numeric: Value to check. Must be a single finite number strictly in |
arg_name |
Character: Argument name to use in error messages. |
Called for side effects. Throws an error if checks fail.
EDG
check_unit_open_scalar(0.5) # Throw error: try(check_unit_open_scalar(0)) try(check_unit_open_scalar(1))check_unit_open_scalar(0.5) # Throw error: try(check_unit_open_scalar(0)) try(check_unit_open_scalar(1))
Check open-unit-interval vector
check_unit_open_vector(x, arg_name = deparse(substitute(x)))check_unit_open_vector(x, arg_name = deparse(substitute(x)))
x |
Numeric: Value to check. Must be a non-empty vector with all elements strictly in
|
arg_name |
Character: Argument name to use in error messages. |
Called for side effects. Throws an error if checks fail.
EDG
check_unit_open_vector(c(0.2, 0.5, 0.9)) # Throw error: try(check_unit_open_vector(c(0, 0.5))) try(check_unit_open_vector(c(0.5, 1)))check_unit_open_vector(c(0.2, 0.5, 0.9)) # Throw error: try(check_unit_open_vector(c(0, 0.5))) try(check_unit_open_vector(c(0.5, 1)))
Clean column names by replacing all spaces and punctuation with a single underscore
clean_colnames(x)clean_colnames(x)
x |
Character vector or matrix with colnames or any object with |
Character vector.
EDG
clean_colnames(iris)clean_colnames(iris)
Clean integer input
clean_int(x, arg_name = deparse(substitute(x)))clean_int(x, arg_name = deparse(substitute(x)))
x |
Double or integer vector to check. |
arg_name |
Character: Name of the variable for error messages. |
The goal is to return an integer vector. If the input is integer, it is returned as is. If the input is numeric, it is coerced to integer only if the numeric values are integers, otherwise an error is thrown.
Integer vector
EDG
clean_int(6L) clean_int(3) # clean_int(12.1) # Error clean_int(c(3, 5, 7)) # clean_int(c(3, 5, 7.01)) # Errorclean_int(6L) clean_int(3) # clean_int(12.1) # Error clean_int(c(3, 5, 7)) # clean_int(c(3, 5, 7.01)) # Error
Clean character vector by replacing all symbols and sequences of symbols with single underscores, ensuring no name begins or ends with a symbol
clean_names(x, prefix_digits = "V_")clean_names(x, prefix_digits = "V_")
x |
Character vector. |
prefix_digits |
Character: prefix to add to names beginning with a digit. Set to NA to skip. |
Character vector.
EDG
x <- c("Patient ID", "_Date-of-Birth", "SBP (mmHg)") x clean_names(x)x <- c("Patient ID", "_Date-of-Birth", "SBP (mmHg)") x clean_names(x)
Check positive integer
clean_posint(x, allow_na = FALSE, arg_name = deparse(substitute(x)))clean_posint(x, allow_na = FALSE, arg_name = deparse(substitute(x)))
x |
Integer vector. |
allow_na |
Logical: If TRUE, NAs are excluded before checking. If FALSE (default), NAs trigger an error. |
arg_name |
Character: Name of the variable for error messages. |
Integer vector of positive values.
EDG
clean_posint(5)clean_posint(5)
Apply 256-color formatting
col256(text, col = "79", bg = FALSE, output_type = c("ansi", "html", "plain"))col256(text, col = "79", bg = FALSE, output_type = c("ansi", "html", "plain"))
text |
Character: Text to color |
col |
Character or numeric: Color (ANSI 256-color code, hex for HTML) |
bg |
Logical: If TRUE, apply as background color |
output_type |
Character: Output type ("ansi", "html", "plain") |
Character: Formatted text with 256-color styling
EDG
col256("Hello", col = 160, output_type = "ansi")col256("Hello", col = 160, output_type = "ansi")
Muted log message gated at verbosity >= 2L. Use for development /
troubleshooting output that should not appear in normal operation.
dbg(..., verbosity = NULL, package = NULL)dbg(..., verbosity = NULL, package = NULL)
... |
Message components, concatenated with no separator. |
verbosity |
Integer or NULL: Overrides |
package |
Character or NULL: Package name for verbosity override. |
Named dbg() rather than debug() to avoid shadowing
base::debug() - the R debugger entry point.
Invisible NULL.
EDG
dbg("payload bytes: ", 1234L)dbg("payload bytes: ", 1234L)
2 Decimal places, otherwise scientific notation
ddSci(x, decimal_places = 2, hi = 1e+06, as_numeric = FALSE)ddSci(x, decimal_places = 2, hi = 1e+06, as_numeric = FALSE)
x |
Vector of numbers |
decimal_places |
Integer: Return this many decimal places. |
hi |
Float: Threshold at or above which scientific notation is used. |
as_numeric |
Logical: If TRUE, convert to numeric before returning.
This will not force all numbers to print 2 decimal places. For example:
1.2035 becomes "1.20" if |
Numbers will be formatted to 2 decimal places, unless this results in 0.00 (e.g. if input was .0032),
in which case they will be converted to scientific notation with 2 significant figures.
ddSci will return 0.00 if the input is exactly zero.
This function can be used to format numbers in plots, on the console, in logs, etc.
Formatted number
EDG
x <- .34876549 ddSci(x) # "0.35" x <- .00000000457823 ddSci(x) # "4.6e-09"x <- .34876549 ddSci(x) # "0.35" x <- .00000000457823 ddSci(x) # "4.6e-09"
S7 property accepting a single non-NA double value.
double_scalardouble_scalar
An S7 property object.
EDG
Returns a new_property() for a character scalar constrained to a fixed set of allowed values.
enum(values, default = NULL, nullable = FALSE)enum(values, default = NULL, nullable = FALSE)
values |
Character: Allowed values. |
default |
Optional Character: Default value. |
nullable |
Logical scalar. If |
An S7 property object.
EDG
type_prop <- enum(c("string", "number", "boolean"), default = "string")type_prop <- enum(c("string", "number", "boolean"), default = "string")
Formats text with specified color, styles, and background using ANSI escape codes or HTML, with support for plain text output.
fmt( x, col = NULL, bold = FALSE, italic = FALSE, underline = FALSE, thin = FALSE, muted = FALSE, bg = NULL, pad = 0L, output_type = c("ansi", "html", "plain") )fmt( x, col = NULL, bold = FALSE, italic = FALSE, underline = FALSE, thin = FALSE, muted = FALSE, bg = NULL, pad = 0L, output_type = c("ansi", "html", "plain") )
x |
Character: Text to format. |
col |
Character: Color (hex code, named color, or NULL for no color). |
bold |
Logical: If TRUE, make text bold. |
italic |
Logical: If TRUE, make text italic. |
underline |
Logical: If TRUE, underline text. |
thin |
Logical: If TRUE, make text thin/light. |
muted |
Logical: If TRUE, make text muted/dimmed. |
bg |
Character: Background color (hex code, named color, or NULL). |
pad |
Integer: Number of spaces to pad before text. |
output_type |
Character: Output type ("ansi", "html", "plain"). |
This function combines multiple formatting options into a single call, making it more efficient than nested function calls. It generates optimized ANSI escape sequences and clean HTML output.
Character: Formatted text with specified styling.
EDG
# Simple color fmt("Hello", col = "red") # Bold red text fmt("Error", col = "red", bold = TRUE) # Multiple styles fmt("Warning", col = "yellow", bold = TRUE, italic = TRUE) # With background fmt("Highlight", col = "white", bg = "blue", bold = TRUE)# Simple color fmt("Hello", col = "red") # Bold red text fmt("Error", col = "red", bold = TRUE) # Multiple styles fmt("Warning", col = "yellow", bold = TRUE, italic = TRUE) # With background fmt("Highlight", col = "white", bg = "blue", bold = TRUE)
Gradient text
fmt_gradient(x, colors, bold = FALSE, output_type = c("ansi", "html", "plain"))fmt_gradient(x, colors, bold = FALSE, output_type = c("ansi", "html", "plain"))
x |
Character: Text to colorize. |
colors |
Character vector: Colors to use for the gradient. |
bold |
Logical: If TRUE, make text bold. |
output_type |
Character: Output type ("ansi", "html", "plain"). |
Character: Text with gradient color applied.
EDG
fmt_gradient("Gradient Text", colors = c("blue", "red")) |> message()fmt_gradient("Gradient Text", colors = c("blue", "red")) |> message()
Formats the $trace carried by an rtemis_error condition (see
abort()) as a numbered, one-line-per-frame string. Most-recent frame
at the bottom, matching base R's traceback() convention. Each frame is
deparsed with a single-line cap so long calls stay readable; no styling
is applied, so the output is safe for any sink (terminal, JSON, HTML).
format_trace(trace, max_width = 80L)format_trace(trace, max_width = 80L)
trace |
|
max_width |
Integer: Max characters per deparsed line. Longer calls are truncated with a trailing ellipsis. |
Character scalar with one frame per \n-separated line,
newest frame last. "" if the trace is empty or NULL.
EDG
## Not run: cond <- tryCatch( check_numeric("oops"), error = identity ) cat(format_trace(cond), "\n") ## End(Not run)## Not run: cond <- tryCatch( check_numeric("oops"), error = identity ) cat(format_trace(cond), "\n") ## End(Not run)
Get output type for printing text.
get_output_type(output_type = c("ansi", "html", "plain"), filename = NULL)get_output_type(output_type = c("ansi", "html", "plain"), filename = NULL)
output_type |
Character vector of output types. |
filename |
Optional Character: Filename for output. |
Exported as internal function for use by other rtemis packages.
Character with selected output type.
EDG
get_output_type()get_output_type()
Reads getOption("<package>.verbosity") first when package is supplied,
falling back to getOption("rtemis.verbosity"), and finally to 1L.
Levels: 0L silent, 1L info/warn/success/abort console echo, 2L
includes debug.
get_verbosity(package = NULL)get_verbosity(package = NULL)
package |
Character or NULL: Optional package-specific override. |
Integer scalar verbosity level.
EDG
get_verbosity()get_verbosity()
A fmt() convenience wrapper for highlighting text.
highlight(x, pad = 0L, output_type = c("ansi", "html", "plain"))highlight(x, pad = 0L, output_type = c("ansi", "html", "plain"))
x |
Character: Text to highlight. |
pad |
Integer: Number of spaces to pad before text. |
output_type |
Character: Output type ("ansi", "html", "plain"). |
Character: Formatted text with highlight.
EDG
message(highlight("This is highlighted!"))message(highlight("This is highlighted!"))
Styled informational message, routed through msg() so it carries the
shared datetime + caller prefix. Fires when verbosity is at least 1L.
info(..., verbosity = NULL, package = NULL)info(..., verbosity = NULL, package = NULL)
... |
Message components, concatenated with no separator. |
verbosity |
Integer or NULL: Overrides |
package |
Character or NULL: Package name for verbosity override
lookup (e.g. |
Invisible NULL.
EDG
info("Server started on port ", 8080L)info("Server started on port ", 8080L)
S7 property accepting a single non-NA integer value (must be integer type, e.g. 1L).
integer_scalarinteger_scalar
An S7 property object.
EDG
Format text for label printing
labelify( x, underscores_to_spaces = TRUE, dotsToSpaces = TRUE, toLower = FALSE, toTitleCase = TRUE, capitalize_strings = c("id"), stringsToSpaces = c("\\$", "`") )labelify( x, underscores_to_spaces = TRUE, dotsToSpaces = TRUE, toLower = FALSE, toTitleCase = TRUE, capitalize_strings = c("id"), stringsToSpaces = c("\\$", "`") )
x |
Character: Input |
underscores_to_spaces |
Logical: If TRUE, convert underscores to spaces. |
dotsToSpaces |
Logical: If TRUE, convert dots to spaces. |
toLower |
Logical: If TRUE, convert to lowercase (precedes |
toTitleCase |
Logical: If TRUE, convert to Title Case. Default = TRUE (This does not change
all-caps words, set |
capitalize_strings |
Character, vector: Always capitalize these strings, if present. Default = |
stringsToSpaces |
Character, vector: Replace these strings with spaces. Escape as needed for |
Character vector.
EDG
x <- c("county_name", "total.cost$", "age", "weight.kg") labelify(x)x <- c("county_name", "total.cost$", "age", "weight.kg") labelify(x)
S7 property accepting a single non-NA logical value.
logical_scalarlogical_scalar
An S7 property object.
EDG
Match Arguments Ignoring Case
match_arg(x, choices)match_arg(x, choices)
x |
Character: Argument to match. |
choices |
Character vector: Choices to match against. |
Character: Matched argument.
EDG
match_arg("papaya", c("AppleExtreme", "SuperBanana", "PapayaMaster"))match_arg("papaya", c("AppleExtreme", "SuperBanana", "PapayaMaster"))
Print message to output with a prefix including data and time, and calling function or full call stack
msg( ..., caller = NULL, call_depth = 1L, caller_id = 1L, newline_pre = FALSE, newline = TRUE, format_fn = plain, sep = " ", verbosity = 1L ) msg0( ..., caller = NULL, call_depth = 1, caller_id = 1, newline_pre = FALSE, newline = TRUE, format_fn = plain, sep = "", verbosity = 1L )msg( ..., caller = NULL, call_depth = 1L, caller_id = 1L, newline_pre = FALSE, newline = TRUE, format_fn = plain, sep = " ", verbosity = 1L ) msg0( ..., caller = NULL, call_depth = 1, caller_id = 1, newline_pre = FALSE, newline = TRUE, format_fn = plain, sep = "", verbosity = 1L )
... |
Message to print |
caller |
Character: Name of calling function |
call_depth |
Integer: Print the system call path of this depth. |
caller_id |
Integer: Which function in the call stack to print |
newline_pre |
Logical: If TRUE begin with a new line. |
newline |
Logical: If TRUE end with a new line. |
format_fn |
Function: Formatting function to use on the message text. |
sep |
Character: Use to separate objects in |
verbosity |
Integer: Verbosity level of the message. If 0L, does not print anything and returns NULL, invisibly. |
If msg is called directly from the console, it will print [interactive>] in place of
the call stack.
msg0, similar to paste0, is msg(..., sep = "")
If verbosity > 0L, returns a list with call, message, and date, invisibly, otherwise returns NULL invisibly.
EDG
msg("Hello")msg("Hello")
msgdone
msgdone(caller = NULL, call_depth = 1, caller_id = 1, sep = " ")msgdone(caller = NULL, call_depth = 1, caller_id = 1, sep = " ")
caller |
Character: Name of calling function |
call_depth |
Integer: Print the system call path of this depth. |
caller_id |
Integer: Which function in the call stack to print |
sep |
Character: Use to separate objects in |
NULL invisibly
EDG
msgstart("Starting process...") msgdone("Process complete")msgstart("Starting process...") msgdone("Process complete")
msgstart
msgstart(..., newline_pre = FALSE, sep = "")msgstart(..., newline_pre = FALSE, sep = "")
... |
Message to print |
newline_pre |
Logical: If TRUE begin with a new line. |
sep |
Character: Use to separate objects in |
NULL invisibly
EDG
msgstart("Starting process...") msgdone("Process complete.")msgstart("Starting process...") msgdone("Process complete.")
S7 property accepting a single finite double greater than or equal to zero, i.e. in .
nonneg_double_scalarnonneg_double_scalar
An S7 property object.
EDG
S7 property accepting a non-empty double vector with all elements finite, greater than or equal to zero, and no NAs.
nonneg_double_vectornonneg_double_vector
An S7 property object.
EDG
S7 property accepting a single non-NA integer value greater than or equal to zero,
i.e. in (e.g. 0L, 1L).
nonneg_integer_scalarnonneg_integer_scalar
An S7 property object.
EDG
Creates an S7 union type that allows for the specified type or NULL.
optional(type)optional(type)
type |
S7 base class or S7 class. |
This should be used when the S7 class already includes all the necessary validation for the
non-NULL case. Otherwise, create a new S7 property with appropriate validator using
S7::new_property().
An S7 union type that allows for the specified type or NULL.
EDG
# Create an optional character type optional(S7::class_character)# Create an optional character type optional(S7::class_character)
S7 property accepting NULL or a single non-NA, non-empty (after trimming whitespace) string.
optional_character_scalaroptional_character_scalar
An S7 property object.
EDG
S7 property accepting NULL or a single non-NA double value.
optional_double_scalaroptional_double_scalar
An S7 property object.
EDG
S7 property accepting NULL or a single non-NA integer value (must be integer type, e.g. 1L).
optional_integer_scalaroptional_integer_scalar
An S7 property object.
EDG
S7 property accepting NULL or a single non-NA logical value.
optional_logical_scalaroptional_logical_scalar
An S7 property object.
EDG
S7 property accepting NULL or a single finite double greater than or equal to zero.
optional_nonneg_double_scalaroptional_nonneg_double_scalar
An S7 property object.
EDG
S7 property accepting NULL or a non-empty double vector with all elements finite,
greater than or equal to zero, and no NAs.
optional_nonneg_double_vectoroptional_nonneg_double_vector
An S7 property object.
EDG
S7 property accepting NULL or a single non-NA integer value greater than or equal to zero.
optional_nonneg_integer_scalaroptional_nonneg_integer_scalar
An S7 property object.
EDG
S7 property accepting NULL or a single finite double strictly greater than zero.
optional_pos_double_scalaroptional_pos_double_scalar
An S7 property object.
EDG
S7 property accepting NULL or a non-empty double vector with all elements finite,
strictly greater than zero, and no NAs.
optional_pos_double_vectoroptional_pos_double_vector
An S7 property object.
EDG
S7 property accepting NULL or a single non-NA integer value strictly greater than zero.
optional_pos_integer_scalaroptional_pos_integer_scalar
An S7 property object.
EDG
S7 property accepting NULL or a single finite double in .
optional_prob_scalaroptional_prob_scalar
An S7 property object.
EDG
S7 property accepting NULL or a non-empty double vector with all elements in
and no NAs.
optional_prob_vectoroptional_prob_vector
An S7 property object.
EDG
S7 property accepting NULL or a single finite double strictly in .
optional_unit_open_scalaroptional_unit_open_scalar
An S7 property object.
EDG
S7 property accepting NULL or a non-empty double vector with all elements strictly in
and no NAs.
optional_unit_open_vectoroptional_unit_open_vector
An S7 property object.
EDG
message()
Force plain text when using message()
plain(x)plain(x)
x |
Character: Text to be output to console. |
Character: Text with ANSI escape codes removed.
EDG
message(plain("hello"))message(plain("hello"))
S7 property accepting a single finite double strictly greater than zero, i.e. in .
pos_double_scalarpos_double_scalar
An S7 property object.
EDG
S7 property accepting a non-empty double vector with all elements finite, strictly greater than zero, and no NAs.
pos_double_vectorpos_double_vector
An S7 property object.
EDG
S7 property accepting a single non-NA integer value strictly greater than zero (e.g. 1L).
pos_integer_scalarpos_integer_scalar
An S7 property object.
EDG
Pretty print a data frame
printdf( x, pad = 0, spacing = 1, ddSci_dp = NULL, transpose = FALSE, justify = "right", colnames = TRUE, rownames = TRUE, column_fmt = highlight, row_fmt = gray, newline_pre = FALSE, newline = FALSE )printdf( x, pad = 0, spacing = 1, ddSci_dp = NULL, transpose = FALSE, justify = "right", colnames = TRUE, rownames = TRUE, column_fmt = highlight, row_fmt = gray, newline_pre = FALSE, newline = FALSE )
x |
data frame |
pad |
Integer: Pad output with this many spaces. |
spacing |
Integer: Number of spaces between columns. |
ddSci_dp |
Integer: Number of decimal places to print using ddSci. Default = NULL for no formatting. |
transpose |
Logical: If TRUE, transpose |
justify |
Character: "right", "left". |
colnames |
Logical: If TRUE, print column names. |
rownames |
Logical: If TRUE, print row names. |
column_fmt |
Formatting fn for printing column names. |
row_fmt |
Formatting fn for printing row names. |
newline_pre |
Logical: If TRUE, print a new line before printing data frame. |
newline |
Logical: If TRUE, print a new line after printing data frame. |
By design, numbers will not be justified, but using ddSci_dp will convert to characters, which will be justified. This is intentional for internal use.
NULL invisibly
EDG
printdf(iris[1:6, ])printdf(iris[1:6, ])
Pretty print a list (or data frame) recursively
printls( x, prefix = "", pad = 2L, item_format = bold, maxlength = 4L, center_title = TRUE, title = NULL, title_newline = TRUE, newline_pre = FALSE, format_fn_rhs = ddSci, print_class = TRUE, abbrev_class_n = 3L, print_df = FALSE, print_S4 = FALSE, limit = 12L )printls( x, prefix = "", pad = 2L, item_format = bold, maxlength = 4L, center_title = TRUE, title = NULL, title_newline = TRUE, newline_pre = FALSE, format_fn_rhs = ddSci, print_class = TRUE, abbrev_class_n = 3L, print_df = FALSE, print_S4 = FALSE, limit = 12L )
x |
list or object that will be converted to a list. |
prefix |
Character: Optional prefix for names. |
pad |
Integer: Pad output with this many spaces. |
item_format |
Formatting function for list item names. |
maxlength |
Integer: Maximum length of items to show using |
center_title |
Logical: If TRUE, autopad title for centering, if present. |
title |
Character: Optional title to print before list. |
title_newline |
Logical: If TRUE, print title on new line. |
newline_pre |
Logical: If TRUE, print newline before list. |
format_fn_rhs |
Formatting function for right-hand side values. |
print_class |
Logical: If TRUE, print abbreviated class of object. |
abbrev_class_n |
Integer: Number of characters to abbreviate class names to. |
print_df |
Logical: If TRUE, print data frame contents, otherwise print n rows and columns. |
print_S4 |
Logical: If TRUE, print S4 object contents, otherwise print class name. |
limit |
Integer: Maximum number of items to show. Use -1 for unlimited. |
Data frames in R began life as lists
NULL invisibly
EDG
printls(list(a = 1:10, b = "Hello", c = list(d = 1, e = 2)), title = "A List")printls(list(a = 1:10, b = "Hello", c = list(d = 1, e = 2)), title = "A List")
S7 property accepting a single finite double in .
prob_scalarprob_scalar
An S7 property object.
EDG
S7 property accepting a non-empty double vector with all elements in and no NAs.
prob_vectorprob_vector
An S7 property object.
EDG
String representation
repr(x, ...)repr(x, ...)
x |
Object to represent as a string. |
... |
Additional arguments passed to methods. |
Character string representation of the object.
EDG
S7::method(repr, S7::class_character) <- function(x, ...) { paste0("<chr> \"", x, "\"") } cat(repr("hello"))S7::method(repr, S7::class_character) <- function(x, ...) { paste0("<chr> \"", x, "\"") } cat(repr("hello"))
Works exactly like printls, but instead of printing to console with cat, it outputs a single string, formatted using mformat, so that cat(repr_ls(x)) looks identical to printls(x) for any list x
repr_ls( x, prefix = "", pad = 2L, item_format = bold, maxlength = 4L, center_title = TRUE, title = NULL, title_newline = TRUE, newline_pre = FALSE, format_fn_rhs = ddSci, print_class = TRUE, abbrev_class_n = 3L, print_df = FALSE, print_S4 = FALSE, limit = 12L, output_type = c("ansi", "html", "plain") )repr_ls( x, prefix = "", pad = 2L, item_format = bold, maxlength = 4L, center_title = TRUE, title = NULL, title_newline = TRUE, newline_pre = FALSE, format_fn_rhs = ddSci, print_class = TRUE, abbrev_class_n = 3L, print_df = FALSE, print_S4 = FALSE, limit = 12L, output_type = c("ansi", "html", "plain") )
x |
list or object that will be converted to a list. |
prefix |
Character: Optional prefix for names. |
pad |
Integer: Pad output with this many spaces. |
item_format |
Formatting function for items. |
maxlength |
Integer: Maximum length of items to show using |
center_title |
Logical: If TRUE, autopad title for centering, if present. |
title |
Character: Title to print before list. |
title_newline |
Logical: If TRUE, print title on new line. |
newline_pre |
Logical: If TRUE, print newline before list. |
format_fn_rhs |
Formatting function for right-hand side of items. |
print_class |
Logical: If TRUE, print abbreviated class of object. |
abbrev_class_n |
Integer: Number of characters to abbreviate class names to. |
print_df |
Logical: If TRUE, print data frame contents, otherwise print n rows and columns. |
print_S4 |
Logical: If TRUE, print S4 object contents, otherwise print class name. |
limit |
Integer: Maximum number of items to show. |
output_type |
Character: Output type for mformat ("ansi", "html", "plain"). |
Exported as internal function for use by other rtemis packages.
Character: Formatted string that can be printed with cat()
EDG
x <- list( a = 1:10, b = "Hello", c = list( d = 1, e = 2 ) ) cat(repr_ls(x, title = "A List"))x <- list( a = 1:10, b = "Hello", c = list( d = 1, e = 2 ) ) cat(repr_ls(x, title = "A List"))
A named vector of colors used in the rtemis ecosystem, provided as hex strings.
rtemis_colorsrtemis_colors
Named character vector of hex color codes.
EDG
rtemis_colors[["teal"]]rtemis_colors[["teal"]]
Removes the SGR / CSI escapes commonly produced by fmt() (and by any
other tool that writes coloured terminal output). Safe to call on plain
input - returns it unchanged.
strip_ansi(x)strip_ansi(x)
x |
Character: Input. |
Character: x with ANSI escapes removed.
EDG
strip_ansi(fmt("hi", col = "red"))strip_ansi(fmt("hi", col = "red"))
Styled success message. Fires when verbosity is at least 1L.
success(..., verbosity = NULL, package = NULL)success(..., verbosity = NULL, package = NULL)
... |
Message components, concatenated with no separator. |
verbosity |
Integer or NULL: Overrides |
package |
Character or NULL: Package name for verbosity override. |
Invisible NULL.
EDG
success("Job ", "abc123", " complete")success("Job ", "abc123", " complete")
Check class of object
test_inherits(x, cl)test_inherits(x, cl)
x |
Object to check |
cl |
Character: class to check against |
Logical
EDG
test_inherits("papaya", "character") # TRUE test_inherits(c(1, 2.5, 3.2), "integer") test_inherits(iris, "list") # FALSE, compare to is_check(iris, is.list)test_inherits("papaya", "character") # TRUE test_inherits(c(1, 2.5, 3.2), "integer") test_inherits(iris, "list") # FALSE, compare to is_check(iris, is.list)
S7 property accepting a single finite double strictly in .
unit_open_scalarunit_open_scalar
An S7 property object.
EDG
S7 property accepting a non-empty double vector with all elements strictly in
and no NAs.
unit_open_vectorunit_open_vector
An S7 property object.
EDG
Styled non-fatal message. By default emits a soft styled message via
msg(); with use_warning = TRUE, calls warning() so callers can
catch via tryCatch(..., warning = handler).
warn(..., use_warning = FALSE, verbosity = NULL, package = NULL)warn(..., use_warning = FALSE, verbosity = NULL, package = NULL)
... |
Message components, concatenated with no separator. |
use_warning |
Logical: If TRUE, signal an R |
verbosity |
Integer or NULL: Overrides |
package |
Character or NULL: Package name for verbosity override. |
Invisible NULL.
EDG
warn("Disk usage at ", 92L, "%")warn("Disk usage at ", 92L, "%")