write.fcat: Write a format catalog to the file system

View source: R/fcat.R

write.fcatR Documentation

Write a format catalog to the file system

Description

The write.fcat function writes a format catalog to the file system. By default, the catalog will be written to the current working directory, using the variable name as the file name. These defaults can be overridden using the appropriate parameters. The catalog will be saved with a file extension of ".fcat".

Usage

write.fcat(x, dir_path = getwd(), file_name = NULL)

Arguments

x

The format catalog to write.

dir_path

The directory path to write the catalog to. Default is the current working directory.

file_name

The name of the file to save the catalog as. Default is the name of the variable that contains the catalog. The ".fcat" file extension will be added automatically.

Value

The full path of the saved format catalog.

See Also

Other fcat: as.data.frame.fcat(), as.fcat(), as.fcat.data.frame(), as.fcat.fmt_lst(), as.fcat.list(), fcat(), is.fcat(), print.fcat(), read.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")
           
# Get temp directory
tmp <- tempdir()            
           
# Save catalog to file system
pth <- write.fcat(c1, dir_path = tmp)

# Read from file system
c2 <- read.fcat(pth)

# 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] "07Jan2024"

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