knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
As of fmtr version 1.2, you can now create a format catalog. A format
catalog is a collection of formats that can be saved, shared, and reused.
The format catalog is created with the
fcat() function. A format catalog
can also be converted to and from a data frame using the
as.fcat() functions. These functions make it easy to store
formatting information as tabular metadata, such as in database tables or
Excel spreadsheets. Here is an example:
# 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) #  "2.0" fapply(c("A", "B", "C", "B"), c1$label_fmt) #  "Label A" "Label B" "Other" "Label B" fapply(Sys.Date(), c1$date_fmt) #  "22Jul2021" # Convert to a data frame dat <- as.data.frame(c1) dat # 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 # Save format catalog for later use write.fcat(c1, tempdir())
Next: Convenience Functions
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.