fattr: Set formatting attributes

View source: R/fattr.R

fattrR Documentation

Set formatting attributes

Description

Assign formatting attributes to a vector.

Usage

fattr(
  x,
  format = NULL,
  width = NULL,
  justify = NULL,
  label = NULL,
  description = NULL,
  keep = TRUE
)

Arguments

x

The vector or data frame column to assign attributes to.

format

The format to assign to the format attribute. The format can be a formatting string, a named vector decode, a vectorized formatting function, or a formatting list.

width

The desired width of the formatted output.

justify

Justification of the output vector. Valid values are 'none', 'left', 'right', 'center', or 'centre'.

label

A label string to assign to the vector. This parameter was added for convenience, as the label is frequently assigned at the same time the formatting attributes are assigned.

description

A description string to assign to the vector. This parameter was added for convenience, as the description is frequently assigned at the same time the formatting attributes are assigned.

keep

Whether to keep any existing formatting attributes and transfer to the new vector. Default value is TRUE.

Details

The fattr function is a convenience function for assigning formatting attributes to a vector. The function accepts parameters for format, width, and justify. Any formatting attributes assigned can be applied using fapply or fdata.

Value

The vector with formatting attributes assigned.

See Also

fdata to apply formats to a data frame, fapply to apply formats to a vector. See FormattingStrings for documentation on formatting strings.

Examples

# Create vector
a <- c(1.3243, 5.9783, 2.3848)

# Assign format attributes
a <- fattr(a, format = "%.1f", width = 10, justify = "center")

# Apply format attributes
fapply(a)
# [1] "   1.3    " "   6.0    " "   2.4    "

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