4444# '
4545# ' # Use formats in the catalog
4646# ' fapply(2, c1$num_fmt)
47+ # ' # [1] "2.0"
48+ # '
4749# ' fapply(c("A", "B", "C", "B"), c1$label_fmt)
50+ # ' # [1] "Label A" "Label B" "Other" "Label B"
51+ # '
4852# ' fapply(Sys.Date(), c1$date_fmt)
53+ # ' # [1] "06Jan2024"
54+ # '
4955# ' @export
5056fcat <- function (... , log = TRUE ) {
5157
@@ -70,7 +76,7 @@ fcat <- function(..., log = TRUE) {
7076# ' @description A generic method for casting objects to
7177# ' a format catalog. Individual objects will inherit from this function.
7278# ' @param x The object to cast.
73- # ' @return A formatting object , created using the information in the
79+ # ' @return A format catalog , created using the information in the
7480# ' input object.
7581# ' @seealso For class-specific methods, see \code{\link{as.fcat.data.frame}},
7682# ' \code{\link{as.fcat.list}}, and \code{\link{as.fcat.fmt_lst}}.
@@ -130,7 +136,6 @@ as.fcat <- function (x) {
130136# ' # Convert catalog to data frame to view the structure
131137# ' df <- as.data.frame(c1)
132138# ' print(df)
133- # '
134139# ' # Name Type Expression Label Order
135140# ' # 1 num_fmt S %.1f NA
136141# ' # 2 label_fmt U x == "A" Label A NA
@@ -140,11 +145,21 @@ as.fcat <- function (x) {
140145# '
141146# ' # Convert data frame back to a format catalog
142147# ' c2 <- as.fcat(df)
148+ # ' c2
149+ # ' # # A format catalog: 3 formats
150+ # ' # - $date_fmt: type S, "%d-%b-%Y"
151+ # ' # - $label_fmt: type U, 3 conditions
152+ # ' # - $num_fmt: type S, "%.1f"
143153# '
144154# ' # Use re-converted catalog
145155# ' fapply(123.456, c2$num_fmt)
156+ # ' # [1] "123.5"
157+ # '
146158# ' fapply(c("A", "B", "C", "B"), c2$label_fmt)
159+ # ' # [1] "Label A" "Label B" "Other" "Label B"
160+ # '
147161# ' fapply(Sys.Date(), c2$date_fmt)
162+ # ' # [1] "07-Jan-2024"
148163# ' @export
149164as.fcat.data.frame <- function (x ) {
150165
@@ -250,7 +265,6 @@ as.fcat.fmt_lst <- function(x) {
250265# ' # Convert catalog to data frame to view the structure
251266# ' df <- as.data.frame(c1)
252267# ' print(df)
253- # '
254268# ' # Name Type Expression Label Order
255269# ' # 1 num_fmt S %.1f NA
256270# ' # 2 label_fmt U x == "A" Label A NA
@@ -260,6 +274,11 @@ as.fcat.fmt_lst <- function(x) {
260274# '
261275# ' # Convert data frame back to a format catalog
262276# ' c2 <- as.fcat(df)
277+ # ' c2
278+ # ' # # A format catalog: 3 formats
279+ # ' # - $date_fmt: type S, "%d%b%Y"
280+ # ' # - $label_fmt: type U, 3 conditions
281+ # ' # - $num_fmt: type S, "%.1f"
263282# ' @export
264283as.data.frame.fcat <- function (x , row.names = NULL , optional = FALSE , ... ) {
265284
@@ -353,8 +372,13 @@ as.data.frame.fcat <- function(x, row.names = NULL, optional = FALSE, ...) {
353372# '
354373# ' # Use formats in the catalog
355374# ' fapply(2, c1$num_fmt)
375+ # ' # [1] "2.0"
376+ # '
356377# ' fapply(c("A", "B", "C", "B"), c1$label_fmt)
378+ # ' # [1] "Label A" "Label B" "Other" "Label B"
379+ # '
357380# ' fapply(Sys.Date(), c1$date_fmt)
381+ # ' # [1] "07Jan2024"
358382# ' @export
359383write.fcat <- function (x , dir_path = getwd(), file_name = NULL ) {
360384
@@ -406,8 +430,13 @@ write.fcat <- function(x, dir_path = getwd(), file_name = NULL) {
406430# '
407431# ' # Use formats in the catalog
408432# ' fapply(2, c1$num_fmt)
433+ # ' # [1] "2.0"
434+ # '
409435# ' fapply(c("A", "B", "C", "B"), c1$label_fmt)
436+ # ' # [1] "Label A" "Label B" "Other" "Label B"
437+ # '
410438# ' fapply(Sys.Date(), c1$date_fmt)
439+ # ' # [1] "07Jan2024"
411440# ' @export
412441read.fcat <- function (file_path ) {
413442
@@ -442,6 +471,10 @@ read.fcat <- function(file_path) {
442471# '
443472# ' # Print the catalog
444473# ' print(c1)
474+ # ' # # A format catalog: 3 formats
475+ # ' # - $num_fmt: type S, "%.1f"
476+ # ' # - $label_fmt: type U, 3 conditions
477+ # ' # - $date_fmt: type S, "%d%b%Y"
445478# ' @import crayon
446479# ' @export
447480print.fcat <- function (x , ... , verbose = FALSE ) {
@@ -524,7 +557,10 @@ print.fcat <- function(x, ..., verbose = FALSE) {
524557# '
525558# ' # Test for "fcat" class
526559# ' is.fcat(c1)
527- # ' is.fcat(Sys.Date())
560+ # ' # [1] TRUE
561+ # '
562+ # ' is.fcat(Sys.Date())
563+ # ' # [1] FALSE
528564# ' @export
529565is.fcat <- function (x ) {
530566
0 commit comments