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.
fcat(..., log = TRUE)
The format catalog object.
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.
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()
# 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")
#> # A user-defined format: 3 conditions
#> Name Type Expression Label Order
#> 1 x U x == "A" Label A NA
#> 2 x U x == "B" Label B NA
#> 3 x U TRUE Other NA
#> # A format catalog: 3 formats
#> - $num_fmt: type S, "%.1f"
#> - $label_fmt: type U, 3 conditions
#> - $date_fmt: type S, "%d%b%Y"
# Use formats in the catalog
fapply(2, c1$num_fmt)
#> [1] "2.0"
# [1] "2.0"
fapply(c("A", "B", "C", "B"), c1$label_fmt)
#> [1] "Label A" "Label B" "Other" "Label B"
# [1] "Label A" "Label B" "Other" "Label B"
fapply(Sys.Date(), c1$date_fmt)
#> [1] "06Oct2025"
# [1] "06Jan2024"