# NOT RUN {
#' ## Example 1: Formatting List - Column Type ##
# Set up data
v1 <- c(Sys.Date(), Sys.Date() + 30, Sys.Date() + 60)
# Create formatting list
fl1 <- flist("%B", "The month is: %s")
# Apply formatting list to vector
fapply(v1, fl1)
## Example 2: Formatting List - Row Type ordered ##
# Set up data
# Notice each row has a different data type
l1 <- list("A", 1.263, as.Date("2020-07-21"),
"B", 5.8732, as.Date("2020-10-17"))
# These formats will be recycled in the order specified
fl2 <- flist(type = "row",
c(A = "Label A", B = "Label B"),
"%.1f",
"%d%b%Y")
fapply(l1, fl2)
## Example 3: Formatting List - Row Type with lookup ##
# Set up data
# Notice each row has a different data type
l2 <- list(2841.258, "H", as.Date("2020-06-19"),
"L", as.Date("2020-04-24"), 1382.8865)
v3 <- c("num", "char", "date", "char", "date", "num")
# Create formatting list
fl3 <- flist(type = "row", lookup = v3,
num = function(x) format(x, digits = 2, nsmall = 1,
big.mark=","),
char = value(condition(x == "H", "High"),
condition(x == "L", "Low"),
condition(TRUE, "NA")),
date = "%d%b%Y")
# Apply formatting list to vector, using lookup
fapply(l2, fl3)
# }
Run the code above in your browser using DataLab