Skip to content

Called on values returned from type_sum() for defining the description in the capital.

Usage

format_type_sum(x, width, ...)

# Default S3 method
format_type_sum(x, width, ...)

# S3 method for class 'AsIs'
format_type_sum(x, width, ...)

Arguments

x

A return value from type_sum()

width

The desired total width. If the returned string still is wider, it will be trimmed. Can be NULL.

...

Arguments passed to methods.

Details

Two methods are implemented by default for this generic: the default method, and the method for the "AsIs" class. Return I("type") from your type_sum() implementation to format the type without angle brackets. For even more control over the formatting, implement your own method.

Examples

# Default method: show the type with angle brackets
format_type_sum(1, NULL)
#> [1] "\033[3m\033[38;5;246m<1>\033[39m\033[23m"
pillar(1)
#> <pillar>
#> <dbl>
#>     1

# AsIs method: show the type without angle brackets
type_sum.accel <- function(x) {
  I("kg m/s^2")
}

accel <- structure(9.81, class = "accel")
pillar(accel)
#> <pillar>
#> kg m/s^2
#> 9.81