| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/type.R |
| 3 |
\name{format_type_sum} |
| 4 |
\alias{format_type_sum} |
| 5 |
\alias{format_type_sum.default} |
| 6 |
\alias{format_type_sum.AsIs} |
| 7 |
\title{Format a type summary} |
| 8 |
\usage{ |
| 9 |
format_type_sum(x, width, ...) |
| 10 |
|
| 11 |
\method{format_type_sum}{default}(x, width, ...) |
| 12 |
|
| 13 |
\method{format_type_sum}{AsIs}(x, width, ...) |
| 14 |
} |
| 15 |
\arguments{ |
| 16 |
\item{x}{A return value from \code{type_sum()}} |
| 17 |
|
| 18 |
\item{width}{The desired total width. If the returned string still is |
| 19 |
wider, it will be trimmed. Can be \code{NULL}.} |
| 20 |
|
| 21 |
\item{...}{Arguments passed to methods.} |
| 22 |
} |
| 23 |
\description{ |
| 24 |
Called on values returned from \code{\link[=type_sum]{type_sum()}} for defining the description |
| 25 |
in the capital. |
| 26 |
} |
| 27 |
\details{ |
| 28 |
Two methods are implemented by default for this generic: the default method, |
| 29 |
and the method for the \code{"AsIs"} class. |
| 30 |
Return \code{I("type")} from your \code{\link[=type_sum]{type_sum()}} implementation to format the type |
| 31 |
without angle brackets. |
| 32 |
For even more control over the formatting, implement your own method. |
| 33 |
} |
| 34 |
\examples{ |
| 35 |
# Default method: show the type with angle brackets |
| 36 |
writeLines(format_type_sum("dbl", width = NULL)) |
| 37 |
pillar(1) |
| 38 |
|
| 39 |
# AsIs method: show the type without angle brackets |
| 40 |
type_sum.accel <- function(x) { |
| 41 |
I("kg m/s^2") |
| 42 |
} |
| 43 |
|
| 44 |
# Typically done through NAMESPACE |
| 45 |
# (perhaps with an @export directive in roxygen2) |
| 46 |
registerS3method("type_sum", "accel", type_sum.accel) |
| 47 |
|
| 48 |
accel <- structure(9.81, class = "accel") |
| 49 |
pillar(accel) |
| 50 |
} |