as.data.frame.fmt_lst: Convert a formatting list to a data frame

Description Usage Arguments Value See Also Examples

View source: R/flist.R

Description

This function takes the information stored in a formatting list, and converts it to a data frame. The data frame format 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

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

Arguments

x

The formatting list to convert.

row.names

Row names for the returned 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 formatting list.

See Also

Other flist: as.flist.data.frame(), as.flist.fcat(), as.flist.list(), as.flist.tbl_df(), as.flist(), flist(), is.flist(), print.fmt_lst()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
# Create a formatting list
c1 <- flist(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 formatting list
c2 <- as.flist(df)

fmtr documentation built on June 21, 2021, 9:06 a.m.