fcat: Create a format catalog

View source: R/fcat.R

fcatR Documentation

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(..., log = TRUE)

Arguments

...

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

log

Whether to log the creation of the format catalog. Default is TRUE. This parameter is used internally.

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.

Other fcat: as.data.frame.fcat(), as.fcat(), as.fcat.data.frame(), as.fcat.fmt_lst(), as.fcat.list(), is.fcat(), print.fcat(), read.fcat(), write.fcat()

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)
# [1] "2.0"

fapply(c("A", "B", "C", "B"), c1$label_fmt)
# [1] "Label A" "Label B" "Other"   "Label B"

fapply(Sys.Date(), c1$date_fmt)
# [1] "06Jan2024"


dbosak01/fmtr documentation built on June 15, 2024, 4:26 a.m.