Learn R Programming

⚠️There's a newer version (1.6.8) of this package.Take me there.

Introduction to fmtr

R has a variety of ways to format data. There are functions for formatting dates, several functions to format numbers, plus you can always do a lookup with a named vector, or write your own vectorized function. Yet there are several problems with the way R handles formatting.

One problem is that there are too many formatting functions. It is not easy to remember which functions do what, and the differences between them. One goal of the fmtr package is to consolidate R's formatting capabilities into a smaller number of functions.

Another problem is when you want to reuse a format. While there are many ways to format data, there is no mechanism to save a format and reuse it later. Therefore, another goal of the fmtr package is to promote format reuse.

A third problem is when you have a complex format that can only be accomplished with multiple formatting functions. It would be nice to have a way to keep these multiple formats together, and assign them all at once.

Finally, there are some formatting activities that are so common, it seems like there should be a function for it. The fmtr package also contains several functions that fall into this category.

Solution

The fmtr package was developed to address the above problems. The package addresses those problems in the following ways:

  1. Two formatting functions: With fmtr, all formatting has been

consolidated into two formatting functions: fapply() and fdata(). fapply() applies a format to a vector. fdata() applies formats to a data frame or tibble. The implementation of the fapply() function is reminiscent of a SAS® put function.

  1. The format catalog: The fmtr package also introduces the concept

of a format catalog to R. A format catalog is a collection of formats that can be saved as a file, shared, and reused. This concept was taken directly from SAS® software.

  1. User-defined format: The fmtr package also improves on the native R

formatting capabilities by introducing the concept of a user-defined format. A user-defined format is an expression-driven lookup. You can define a set of logical expressions that, when true, will return a corresponding lookup value. The implementation of the user-defined format is similar to a SAS® user-defined format.

  1. The formatting list: For complicated formats that require more than

one function, the fmtr package also introduces the concept of a formatting list. A formatting list can perform operations that are difficult to accomplish otherwise.

  1. Helper and Convenience functions: Finally, the fmtr package contains

a set of functions to help you with common formatting tasks. For instance, it has functions to assist in assigning formatting attributes to an entire data frame. It also has some ready-made functions to perform very common types of statistical formatting.

All together, the above capabilities make formatting with the fmtr package both simpler and more powerful. The reuse features also make R more suitable to team programming.

For additional reading, examples, and a complete function reference, refer to the fmtr documentation site here.

Installation

To install the fmtr package, you may do so by running the following command from your R console:

install.packages("fmtr")

Then put the following line at the top of your script:

library(fmtr)

The fmtr package will then be loaded, and available for use in your project.

For examples and usage information, please visit the fmtr documentation site here. These examples will demonstrate the extraordinary usefulness of the formatting functions, and give you many ideas on how and where to use the fmtr package.

Getting Help

If you need help with the fmtr package, the best place to turn to is the fmtr web site. This web site offers many examples, and full documentation on every function.

If you want to look at the code for the fmtr package, visit the github page here.

If you encounter a bug or have a feature request, please submit your issue here

See Also

The fmtr package is part of the sassy meta-package. The sassy meta-package includes several packages that help make R easier for SAS® programmers. You can read more about the sassy package here.

Copy Link

Version

Install

install.packages('fmtr')

Monthly Downloads

1,850

Version

1.6.5

License

CC0

Issues

Pull Requests

Stars

Forks

Maintainer

David Bosak

Last Published

June 13th, 2024

Functions in fmtr (1.6.5)

as.flist.data.frame

Convert a data frame to a formatting list
as.flist.tbl_df

Convert a tibble to a formatting list
fapply2

Apply formatting to two vectors
as.fmt

Generic casting method for formats
as.flist.fcat

Convert a format catalog to a formatting list
fapply

Apply formatting to a vector
condition

Define a condition for a user-defined format
descriptions

Get or set descriptions for data frame columns
as.flist.list

Convert a list to a formatting list
as.fmt.data.frame

Convert a data frame to a user-defined format
fmt_mean_sd

Formatted mean and standard deviation
fmt_n

Formatted Count
fmt_quantile_range

Formatted Quantile Range
fmt_median

Formatted Median
fattr<-

Set formatting attributes
fmt_range

Formatted Range
fattr

Set formatting attributes
fdata

Format a data frame or tibble
fcat

Create a format catalog
is.format

Determine whether an object is a user-defined format
is.flist

Is object a formatting list
labels.fmt

Extract labels from a user-defined format
justification

Get or set justification for data frame columns
formats

Get or set formats for a data frame
is.fcat

Class test for a format catalog
write.flist

Write a formatting list to the file system
fmt_cnt_pct

Formatted count and percent
flist

Create a formatting list
print.fmt

Print a format
read.flist

Read a formatting list from the file system
widths

Get or set column widths for a data frame
print.fcat

Print a format catalog
value

Create a user-defined format
read.fcat

Read a format catalog from the file system
print.fmt_lst

Print a formatting list
fmtr

A package for formatting data
write.fcat

Write a format catalog to the file system
FormattingStrings

Formatting Strings
as.data.frame.fmt

Casts a format to a data frame
as.data.frame.fcat

Convert a format catalog to a data frame
as.data.frame.fmt_lst

Convert a formatting list to a data frame
as.fcat.tbl_df

Convert a tibble to a format catalog
as.flist

Convert to a formatting list
as.fcat.fmt_lst

Convert a formatting list to a format catalog
as.fcat.list

Convert a list to a format catalog
as.fcat

Generic casting method for format catalogs
as.fcat.data.frame

Convert a data frame to a format catalog