widths: Get or set column widths for a data frame

Description Usage Arguments Details Value See Also Examples

View source: R/widths.R

Description

The widths function extracts all assigned widths from a data frame, and returns them in a named list. The function also assigns widths from a named list.

Usage

1
2
3
widths(x)

widths(x) <- value

Arguments

x

A data frame or tibble

value

A named list of widths. The widths must be positive integers greater than zero.

Details

If widths are assigned to the "width" attributes of the data frame columns, the widths function will extract those widths. The function will return the widths in a named list, where the names correspond to the name of the column that the width was assigned to. If a column does not have a width attribute assigned, that column will not be included in the list.

When used on the receiving side of an assignment, the function will assign widths to a data frame. The widths should be in a named list, where each name corresponds to the data frame column to assign the width to.

Value

A named list of widths. The widths must be positive integers greater than zero.

See Also

fdata to display formatted data, value to create user-defined formats, and fapply to apply formats to a vector.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# Take subset of data
df1 <- mtcars[1:10, c("mpg", "cyl") ]

# Print current state
print(df1)

# Assign widths
widths(df1) <- list(mpg = 12, cyl = 10) 

# Display formatted data
fdata(df1)

# View assigned widths
widths(df1)

fmtr documentation built on July 25, 2021, 9:06 a.m.