fmt_int: Convert integers into same-length strings

View source: R/fmt_int.R

fmt_intR Documentation

Convert integers into same-length strings

Description

Converts an integer value or vector of integer values into string(s) without any decimal point, padding them with a leading character to ensure they are all the same length.

Usage

fmt_int(num, tol = 1e-08, pad_char = " ", preserve_names = FALSE)

Arguments

num

An integer vector of values to be converted (these do not need to be of class integer but they do need to be 'integerish', i.e. without any digits after the decimal points).

tol

The numerical tolerance used to check whether a double can be safely converted to an integer.

pad_char

The character to use for (left) padding to ensure same-length output.

preserve_names

TRUE to preserve names from the input vector, FALSE otherwise.

Value

A character vector of formatted integer values, left-padded to the length of the largest value with the specified padding character.

Examples

fmt_int(2) # => "2"
fmt_int(2.0) # => "2"
fmt_int(2.00001, tol = 1.0e-4) # => "2"
fmt_int(c(2, 467, 25)) # => [1] "  2" "467" " 25"
fmt_int(c(2, 467, 25), pad_char=".") # => [1] "..2" "467" ".25"
fmt_int(c(a = 1, b = 20), preserve_names = TRUE)


toniprice/jute documentation built on Jan. 11, 2023, 8:23 a.m.