Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

fcat

Create a format catalog


Description

A format catalog is a collection of formats. A format collection allows you to manage and store formats as a unit. The fcat function defines the format catalog.

Usage

fcat(...)

Arguments

...

A set of formats. Pass the formats as a name/value pair. Multiple name/value pairs are separated by a comma.

Details

A format catalog is an S3 object of class "fcat". The purpose of the catalog is to combine related formats, and allow you to manipulate all of them as a single object. The format catalog can be saved to/from a file using the write.fcat and read.fcat functions. A format catalog can also be converted to/from a data frame using the as.fcat.data.frame and as.data.frame.fcat functions. Formats are accessed in the catalog using list syntax.

A format catalog can be used to assign formats to a data frame or tibble using the formats function. Formats may be applied using the fdata and fapply functions.

A format catalog may contain any type of format except a formatting list. Allowed formats include a formatting string, a named vector lookup, a user-defined format, and a vectorized formatting function. A formatting list can be converted to a format catalog and saved independently. See the flist function for more information on formatting lists.

Value

The format catalog object.

See Also

formats function for assigning formats to a data frame, and the fdata and fapply functions for applying formats.

Examples

# Create format catalog
c1 <- fcat(num_fmt  = "%.1f",
           label_fmt = value(condition(x == "A", "Label A"),
                             condition(x == "B", "Label B"),
                             condition(TRUE, "Other")),
           date_fmt = "%d%b%Y")

# Use formats in the catalog
fapply(2, c1$num_fmt)
fapply(c("A", "B", "C", "B"), c1$label_fmt)
fapply(Sys.Date(), c1$date_fmt)

fmtr

Easily Apply Formats to Data

v1.5.0
CC0
Authors
David Bosak
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.