fmt_spec: Format Specification

Description Usage Arguments Details Value

Description

The function fmt_spec is used to create a format specification object which describes how a number is to be formatted. The function as_fmt_spec parses a string with a concise representation of the specification into a fmt_spec object.

Usage

1
2
3
4
5
as_fmt_spec(x = character())

fmt_spec(fill = " ", align = c(">", "<", "^", "="), sign = c("-", "+",
  "(", " "), symbol = NULL, zero = FALSE, width = NULL, comma = FALSE,
  precision = NULL, type = NULL)

Arguments

x

A string representation of the spec. See Details.

fill

A string. See Details.

align

A string. See Details.

sign

A string. See Details.

symbol

A string. See Details.

zero

A logical vector of length one. See Details.

width

An integer vector of length one. See Details.

comma

An logical vector of length one. See Details.

precision

An integer vector of length one. See Details.

type

A character vector of length one. See Details.

Details

The returned function takes a number as the only argument, and returns a string representing the formatted number. The general form of a specifier is: [[fill]align][sign][symbol][0][width][,][.precision][type]

The fill can be any character. The presence of a fill character is signaled by the *align* character following it, which must be one of the following:

The sign can be:

The symbol can be:

The zero (0) option enables zero-padding; this implicitly sets fill to "0" and align to "=".

The width defines the minimum field width; if not specified, then the width will be determined by the content.

The comma (",") option enables the use of a group separator, such as a comma for thousands. The grouping mark and intervals are specified by the locale.

Depending on the type, the precision either indicates the number of digits that follow the decimal point ("f", "%"), or the number of significant digits (NULL, "a", "e", "g", "r", "s", "p"). If the precision is not specified, it defaults to 6 for all types except NULL, which defaults to 12. The recision is ignored for integer formats (types "b", "o", "d", "x", "X" and "c"). See precision_fixed and precision_round for help picking an appropriate precision.

The available type values are:

Note that these formats are not the same as those in sprintf.

Value

An object of class "fmt_spec". This is a list with elements:

fill

Character vector of length one. See Details.

align

Character vector of length one. See Details.

sign

Character vector of length one. See Details.

symbol

Character vector of length one. See Details.

width

Integer vector of length one. See Details.

comma

Logical vector of length one. See Details.

precision

Integer vector of length one.

type

Character vector of length one, or NULL if the default type


jrnold/fivemat documentation built on May 20, 2019, 1 a.m.