Skip to contents

Flexible way to format deb_lsd, deb_decimal, and deb_tetra vectors for use as labels or text.

Usage

deb_text(x, ...)

# S3 method for default
deb_text(x, ...)

# S3 method for deb_lsd
deb_text(
  x,
  digits = 0,
  currency = "£",
  l.mark = "",
  s.mark = "s.",
  d.mark = "d.",
  sep = " ",
  big.mark = ",",
  decimal.mark = ".",
  suffix = "",
  ...
)

# S3 method for deb_decimal
deb_text(
  x,
  digits = 0,
  currency = "£",
  big.mark = ",",
  decimal.mark = ".",
  suffix = "",
  ...
)

# S3 method for deb_tetra
deb_text(
  x,
  digits = 0,
  currency = "£",
  l.mark = "",
  s.mark = "s.",
  d.mark = "d.",
  f.mark = "f.",
  sep = " ",
  big.mark = ",",
  decimal.mark = ".",
  suffix = "",
  ...
)

Arguments

x

A vector of class deb_lsd, deb_decimal, or deb_tetra.

...

Arguments passed on to further methods.

digits

Desired number of digits after the decimal mark to which to round the numeric values. Default is 0.

currency

Character used for the currency mark. Default is pound sign.

l.mark

Character used following the pounds (l) unit. Default is "".

s.mark

Character used following the shillings (s) unit. Default is "s.".

d.mark

Character used following the pence (d) unit. Default is "d.".

sep

Character to separate pounds, shillings, pence, and optionally farthing units. Default is " ".

big.mark

Character used to mark intervals to the left of the decimal mark. Default is "," with default big.interval of 3.

decimal.mark

Character used for decimal mark. Default is ".".

suffix

Character placed after the values. Default is "".

f.mark

Character used following the farthing (f) unit with tetrapartite values. Default is "f.".

Value

A Character vector of formatted values.

Details

deb_text is similar to as.character() in that both return a character vector of the values of deb_lsd, deb_decimal, and deb_tetra vectors. However, as.character() uses the normal printing method for these vectors. deb_text() provides a convenient way to nicely format deb_lsd, deb_decimal, and deb_tetra vectors for use as text or labels with options for customization.

deb_text() uses formatC() to format the numeric values of x. Numbers are printed in non-scientific format and trailing zeros are dropped.

All character vector arguments should be length 1.

See also

formatC() for further options passed to ....

Examples

lsd <- deb_lsd(l = c(10000, 0, -10000),
               s = c(8, 0, -8),
               d = c(5.8252, 0, -5.8252))
dec <- deb_decimal(c(10000.8252, 0, -10000.8252))
tetra <- deb_tetra(l = c(10000, 0, -10000),
                   s = c(8, 0, -8),
                   d = c(5, 0, -5),
                   f = c(2.8252, 0, -2.8252))

deb_text(lsd)
#> [1] "£10,000 8s. 6d."  "£0 0s. 0d."       "-£10,000 8s. 6d."
deb_text(dec)
#> [1] "£10,001"  "£0"       "-£10,001"
deb_text(tetra)
#> [1] "£10,000 8s. 5d. 3f."  "£0 0s. 0d. 0f."       "-£10,000 8s. 5d. 3f."

# Compact format for deb_lsd with suffix to distinguish currency
deb_text(lsd, s.mark = "", d.mark = "",
         sep = ".", suffix = " Flemish")
#> [1] "£10,000.8.6 Flemish"  "£0.0.0 Flemish"       "-£10,000.8.6 Flemish"

# Control the number of digits
deb_text(lsd, digits = 3)
#> [1] "£10,000 8s. 5.825d."  "£0 0s. 0d."           "-£10,000 8s. 5.825d."
deb_text(dec, digits = 3)
#> [1] "£10,000.825"  "£0"           "-£10,000.825"
deb_text(tetra, digits = 3)
#> [1] "£10,000 8s. 5d. 2.825f."  "£0 0s. 0d. 0f."          
#> [3] "-£10,000 8s. 5d. 2.825f."

# Change big mark and decimal mark
deb_text(lsd, digits = 4, big.mark = ".", decimal.mark = ",")
#> [1] "£10.000 8s. 5,8252d."  "£0 0s. 0d."            "-£10.000 8s. 5,8252d."
deb_text(dec, digits = 4, big.mark = ".", decimal.mark = ",")
#> [1] "£10.000,8252"  "£0"            "-£10.000,8252"
deb_text(tetra, digits = 4, big.mark = ".", decimal.mark = ",")
#> [1] "£10.000 8s. 5d. 2,8252f."  "£0 0s. 0d. 0f."           
#> [3] "-£10.000 8s. 5d. 2,8252f."