Title: | Create Values for Human Consumption |
---|---|
Description: | An almost direct port of the 'python' 'humanize' package <https://github.com/jmoiron/humanize>. This package contains utilities to convert values into human readable forms. |
Authors: | Gerry Manoim [aut, cre] |
Maintainer: | Gerry Manoim <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.2.0 |
Built: | 2025-02-12 05:57:09 UTC |
Source: | https://github.com/gerrymanoim/humanize |
Convert to AP Number
count_as_ap(value)
count_as_ap(value)
value |
A single positive integer |
For numbers 1-9, returns the number spelled out. Otherwise, returns the number as a string.
count_as_ap(3) count_as_ap(20)
count_as_ap(3) count_as_ap(20)
Transform a count to an ordinal string
count_as_ordinal(value)
count_as_ordinal(value)
value |
A single positive integer |
A string with the ordinal representation of a number
count_as_ordinal(1) count_as_ordinal(111)
count_as_ordinal(1) count_as_ordinal(111)
Note - currently limited to .Machine$integer.max
.
count_as_word(value, fmt = "%.1f")
count_as_word(value, fmt = "%.1f")
value |
A single positive integer |
fmt |
Extra number formatting supplied to sprintf |
Returns a string with the power of a number replaced by the appropriate word.
count_as_word(100) count_as_word(1000000) count_as_word(1200000000)
count_as_word(100) count_as_word(1000000) count_as_word(1200000000)
Like natural day, but will append a year for dates that are a year or more in the past or future
natural_date(value)
natural_date(value)
value |
A Date value |
natural_day
natural_date(Sys.Date()) natural_date(Sys.Date()-10)
natural_date(Sys.Date()) natural_date(Sys.Date()-10)
For date values that are tomorrow, today or yesterday compared to present day
returns representing string. Otherwise, returns a string formatted according
to fmt
natural_day(value, fmt = "%b %d")
natural_day(value, fmt = "%b %d")
value |
A date value |
fmt |
Optional formatting string for dates not yesterday, today, tomorrow |
A nicely formatted date
natural_day(Sys.Date()) natural_day(Sys.Date()-10)
natural_day(Sys.Date()) natural_day(Sys.Date()-10)
Convert bytes to a more natural representation
natural_size(bytes, suffix_type = "decimal", fmt = "%.1f")
natural_size(bytes, suffix_type = "decimal", fmt = "%.1f")
bytes |
Number of bytes |
suffix_type |
One of 'decimal', 'binary', 'gnu' |
fmt |
Extra number formatting |
natural_size(3000)
natural_size(3000)
Given a datetime or a number of seconds, return a natural representation of that resolution that makes sense. Ago/From now determined by positive or negative values.
natural_time(value, use_months = TRUE)
natural_time(value, use_months = TRUE)
value |
a datetime or a number of seconds |
use_months |
Boolean whether we should (imprecisely) use months as a unit |
natural_time(Sys.time()-1) natural_time(Sys.time()-100)
natural_time(Sys.time()-1) natural_time(Sys.time()-100)
Just a wrapper around format
with defaults for full digits
number_as_comma(value)
number_as_comma(value)
value |
A numeric |
A string with comma separation every three digits
number_as_comma(1000) number_as_comma(10000)
number_as_comma(1000) number_as_comma(10000)
Takes in a number of seconds and computes a "human" delta
seconds_to_natural_delta(seconds, use_months = TRUE)
seconds_to_natural_delta(seconds, use_months = TRUE)
seconds |
A positive number of seconds |
use_months |
Boolean whether we should (imprecisely) use months as a unit |
natural_time