as.data.frame.fcat: Convert a format catalog to a data frame

View source: R/fcat.R

as.data.frame.fcatR Documentation

Convert a format catalog to a data frame

Description

This function takes the information stored in a format catalog, and converts it to a data frame. This data frame is useful for storage, editing, saving to a spreadsheet, etc. The data frame shows the name of the formats, their type, and the format expression. For user-defined formats, the data frame populates additional columns for the label and order.

Usage

## S3 method for class 'fcat'
as.data.frame(x, row.names = NULL, optional = FALSE, ...)

Arguments

x

The format catalog to convert.

row.names

Row names of the return data frame. Default is NULL.

optional

TRUE or FALSE value indicating whether converting to syntactic variable names is desired. In the case of formats, the resulting data frame will always be returned with syntactic names, and this parameter is ignored.

...

Any follow-on parameters.

Value

A data frame that contains the values stored in the format catalog.

See Also

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

Examples

# Create a 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")
           
# Convert catalog to data frame to view the structure
df <- as.data.frame(c1)
print(df)
#       Name Type Expression   Label Order
# 1   num_fmt    S       %.1f            NA
# 2 label_fmt    U   x == "A" Label A    NA
# 3 label_fmt    U   x == "B" Label B    NA
# 4 label_fmt    U       TRUE   Other    NA
# 5  date_fmt    S     %d%b%Y            NA

# Convert data frame back to a format catalog
c2 <- as.fcat(df)
c2
# # A format catalog: 3 formats
# - $date_fmt: type S, "%d%b%Y"
# - $label_fmt: type U, 3 conditions
# - $num_fmt: type S, "%.1f"

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