Title: | Pretty, Human Readable Formatting of Quantities |
---|---|
Description: | Pretty, human readable formatting of quantities. Time intervals: '1337000' -> '15d 11h 23m 20s'. Vague time intervals: '2674000' -> 'about a month ago'. Bytes: '1337' -> '1.34 kB'. Rounding: '99' with 3 significant digits -> '99.0' p-values: '0.00001' -> '<0.0001'. Colors: '#FF0000' -> 'red'. Quantities: '1239437' -> '1.24 M'. |
Authors: | Gabor Csardi [aut, cre], Bill Denney [ctb] , Christophe Regouby [ctb], Posit Software, PBC [cph, fnd] |
Maintainer: | Gabor Csardi <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.2.0.9000 |
Built: | 2024-11-11 06:00:21 UTC |
Source: | https://github.com/r-lib/prettyunits |
Use pretty_bytes()
to format bytes. compute_bytes()
is the underlying
engine that may be useful for custom formatting.
pretty_bytes(bytes, style = c("default", "nopad", "6")) compute_bytes(bytes, smallest_unit = "B")
pretty_bytes(bytes, style = c("default", "nopad", "6")) compute_bytes(bytes, smallest_unit = "B")
bytes |
Numeric vector, number of bytes. |
style |
Formatting style:
|
smallest_unit |
A character scalar, the smallest unit to use. |
Character vector, the formatted sizes.
For compute_bytes
, a data frame with columns amount
, unit
,
negative
.
bytes <- c(1337, 133337, 13333337, 1333333337, 133333333337) pretty_bytes(bytes) pretty_bytes(bytes, style = "nopad") pretty_bytes(bytes, style = "6")
bytes <- c(1337, 133337, 13333337, 1333333337, 133333333337) pretty_bytes(bytes) pretty_bytes(bytes, style = "nopad") pretty_bytes(bytes, style = "6")
Color definition (like RGB) to a name
pretty_color(color) pretty_colour(color)
pretty_color(color) pretty_colour(color)
color |
A scalar color that is usable as an input to |
A character string that is the closest named colors to the input color. The output will have an attribute of alternate color names (named "alt").
Pretty formatting of time intervals (difftime objects)
pretty_dt(dt, compact = FALSE)
pretty_dt(dt, compact = FALSE)
dt |
A |
compact |
If true, then only the first non-zero unit is used. See examples below. |
Character vector of formatted time intervals.
Other time:
pretty_ms()
,
pretty_sec()
pretty_dt(as.difftime(1000, units = "secs")) pretty_dt(as.difftime(0, units = "secs"))
pretty_dt(as.difftime(1000, units = "secs")) pretty_dt(as.difftime(0, units = "secs"))
Pretty formatting of milliseconds
pretty_ms(ms, compact = FALSE)
pretty_ms(ms, compact = FALSE)
ms |
Numeric vector of milliseconds |
compact |
If true, then only the first non-zero unit is used. See examples below. |
Character vector of formatted time intervals.
Other time:
pretty_dt()
,
pretty_sec()
pretty_ms(c(1337, 13370, 133700, 1337000, 1337000000)) pretty_ms(c(1337, 13370, 133700, 1337000, 1337000000), compact = TRUE)
pretty_ms(c(1337, 13370, 133700, 1337000, 1337000000)) pretty_ms(c(1337, 13370, 133700, 1337000, 1337000000), compact = TRUE)
Use pretty_num()
to format numbers compute_num()
is the underlying
engine that may be useful for custom formatting.
pretty_num(number, style = c("default", "nopad", "6")) compute_num(number, smallest_prefix = "y")
pretty_num(number, style = c("default", "nopad", "6")) compute_num(number, smallest_prefix = "y")
number |
Numeric vector, number related to a linear quantity. |
style |
Formatting style:
|
smallest_prefix |
A character scalar, the smallest prefix to use. |
Character vector, the formatted sizes.
For compute_num
, a data frame with columns amount
, prefix
,
negative
.
numbers <- c(1337, 1.3333e-5, 13333337, 1333333337, 133333333337) pretty_num(numbers) pretty_num(numbers, style = "nopad") pretty_num(numbers, style = "6")
numbers <- c(1337, 1.3333e-5, 13333337, 1333333337, 133333333337) pretty_num(numbers) pretty_num(numbers, style = "nopad") pretty_num(numbers, style = "6")
p-values in a human-readable string
pretty_p_value(x, minval = 1e-04)
pretty_p_value(x, minval = 1e-04)
x |
A numeric vector. |
minval |
The minimum p-value to show (lower values will show as
|
A character vector of p-value representations.
pretty_p_value(c(1, 0, NA, 0.01, 0.0000001)) pretty_p_value(c(1, 0, NA, 0.01, 0.0000001), minval = 0.05)
pretty_p_value(c(1, 0, NA, 0.01, 0.0000001)) pretty_p_value(c(1, 0, NA, 0.01, 0.0000001), minval = 0.05)
Round a value to a defined number of digits printing out trailing zeros, if applicable
pretty_round(x, digits = 0, sci_range = Inf, sci_sep = "e")
pretty_round(x, digits = 0, sci_range = Inf, sci_sep = "e")
x |
The number to round. |
digits |
integer indicating the number of decimal places. |
sci_range |
See help for |
sci_sep |
The separator to use for scientific notation strings (typically this will be either "e" or "x10^" for computer- or human-readable output). |
Values that are not standard numbers like Inf
, NA
, and
NaN
are returned as "Inf"
, "NA"
, and "NaN"
.
A string with the value.
Pretty formatting of seconds
pretty_sec(sec, compact = FALSE)
pretty_sec(sec, compact = FALSE)
sec |
Numeric vector of seconds. |
compact |
If true, then only the first non-zero unit is used. See examples below. |
Character vector of formatted time intervals.
Other time:
pretty_dt()
,
pretty_ms()
pretty_sec(c(1337, 13370, 133700, 1337000, 13370000)) pretty_sec(c(1337, 13370, 133700, 1337000, 13370000), compact = TRUE)
pretty_sec(c(1337, 13370, 133700, 1337000, 13370000)) pretty_sec(c(1337, 13370, 133700, 1337000, 13370000), compact = TRUE)
Round a value to a defined number of significant digits printing out trailing zeros, if applicable
pretty_signif(x, digits = 6, sci_range = 6, sci_sep = "e")
pretty_signif(x, digits = 6, sci_range = 6, sci_sep = "e")
x |
The number to round. |
digits |
integer indicating the number of significant digits. |
sci_range |
integer (or |
sci_sep |
The separator to use for scientific notation strings (typically this will be either "e" or "x10^" for computer- or human-readable output). |
Values that are not standard numbers like Inf
, NA
, and
NaN
are returned as "Inf"
, "NA"
, and NaN
.
A string with the value.
It calls vague_dt
to do the actual formatting.
time_ago(date, format = c("default", "short", "terse"))
time_ago(date, format = c("default", "short", "terse"))
date |
Date(s), |
format |
Format, currently available formats are: ‘default’, ‘short’, ‘terse’. See examples below. |
Character vector of the formatted time intervals.
now <- Sys.time() time_ago(now) time_ago(now - as.difftime(30, units = "secs")) time_ago(now - as.difftime(14, units = "mins")) time_ago(now - as.difftime(5, units = "hours")) time_ago(now - as.difftime(25, units = "hours")) time_ago(now - as.difftime(5, units = "days")) time_ago(now - as.difftime(30, units = "days")) time_ago(now - as.difftime(365, units = "days")) time_ago(now - as.difftime(365 * 10, units = "days")) ## Short format time_ago(format = "short", now) time_ago(format = "short", now - as.difftime(30, units = "secs")) time_ago(format = "short", now - as.difftime(14, units = "mins")) time_ago(format = "short", now - as.difftime(5, units = "hours")) time_ago(format = "short", now - as.difftime(25, units = "hours")) time_ago(format = "short", now - as.difftime(5, units = "days")) time_ago(format = "short", now - as.difftime(30, units = "days")) time_ago(format = "short", now - as.difftime(365, units = "days")) time_ago(format = "short", now - as.difftime(365 * 10, units = "days")) ## Even shorter, terse format, (almost always) exactly 3 characters wide time_ago(format = "terse", now) time_ago(format = "terse", now - as.difftime(30, units = "secs")) time_ago(format = "terse", now - as.difftime(14, units = "mins")) time_ago(format = "terse", now - as.difftime(5, units = "hours")) time_ago(format = "terse", now - as.difftime(25, units = "hours")) time_ago(format = "terse", now - as.difftime(5, units = "days")) time_ago(format = "terse", now - as.difftime(30, units = "days")) time_ago(format = "terse", now - as.difftime(365, units = "days")) time_ago(format = "terse", now - as.difftime(365 * 10, units = "days"))
now <- Sys.time() time_ago(now) time_ago(now - as.difftime(30, units = "secs")) time_ago(now - as.difftime(14, units = "mins")) time_ago(now - as.difftime(5, units = "hours")) time_ago(now - as.difftime(25, units = "hours")) time_ago(now - as.difftime(5, units = "days")) time_ago(now - as.difftime(30, units = "days")) time_ago(now - as.difftime(365, units = "days")) time_ago(now - as.difftime(365 * 10, units = "days")) ## Short format time_ago(format = "short", now) time_ago(format = "short", now - as.difftime(30, units = "secs")) time_ago(format = "short", now - as.difftime(14, units = "mins")) time_ago(format = "short", now - as.difftime(5, units = "hours")) time_ago(format = "short", now - as.difftime(25, units = "hours")) time_ago(format = "short", now - as.difftime(5, units = "days")) time_ago(format = "short", now - as.difftime(30, units = "days")) time_ago(format = "short", now - as.difftime(365, units = "days")) time_ago(format = "short", now - as.difftime(365 * 10, units = "days")) ## Even shorter, terse format, (almost always) exactly 3 characters wide time_ago(format = "terse", now) time_ago(format = "terse", now - as.difftime(30, units = "secs")) time_ago(format = "terse", now - as.difftime(14, units = "mins")) time_ago(format = "terse", now - as.difftime(5, units = "hours")) time_ago(format = "terse", now - as.difftime(25, units = "hours")) time_ago(format = "terse", now - as.difftime(5, units = "days")) time_ago(format = "terse", now - as.difftime(30, units = "days")) time_ago(format = "terse", now - as.difftime(365, units = "days")) time_ago(format = "terse", now - as.difftime(365 * 10, units = "days"))
Human readable format of a time interval
vague_dt(dt, format = c("default", "short", "terse"))
vague_dt(dt, format = c("default", "short", "terse"))
dt |
A |
format |
Format, currently available formats are: ‘default’, ‘short’, ‘terse’. See examples below. |
Character vector of the formatted time intervals.
vague_dt(as.difftime(30, units = "secs")) vague_dt(as.difftime(14, units = "mins")) vague_dt(as.difftime(5, units = "hours")) vague_dt(as.difftime(25, units = "hours")) vague_dt(as.difftime(5, units = "days")) vague_dt(as.difftime(30, units = "days")) vague_dt(as.difftime(365, units = "days")) vague_dt(as.difftime(365 * 10, units = "days")) ## Short format vague_dt(format = "short", as.difftime(30, units = "secs")) vague_dt(format = "short", as.difftime(14, units = "mins")) vague_dt(format = "short", as.difftime(5, units = "hours")) vague_dt(format = "short", as.difftime(25, units = "hours")) vague_dt(format = "short", as.difftime(5, units = "days")) vague_dt(format = "short", as.difftime(30, units = "days")) vague_dt(format = "short", as.difftime(365, units = "days")) vague_dt(format = "short", as.difftime(365 * 10, units = "days")) ## Even shorter, terse format, (almost always) exactly 3 characters wide vague_dt(format = "terse", as.difftime(30, units = "secs")) vague_dt(format = "terse", as.difftime(14, units = "mins")) vague_dt(format = "terse", as.difftime(5, units = "hours")) vague_dt(format = "terse", as.difftime(25, units = "hours")) vague_dt(format = "terse", as.difftime(5, units = "days")) vague_dt(format = "terse", as.difftime(30, units = "days")) vague_dt(format = "terse", as.difftime(365, units = "days")) vague_dt(format = "terse", as.difftime(365 * 10, units = "days"))
vague_dt(as.difftime(30, units = "secs")) vague_dt(as.difftime(14, units = "mins")) vague_dt(as.difftime(5, units = "hours")) vague_dt(as.difftime(25, units = "hours")) vague_dt(as.difftime(5, units = "days")) vague_dt(as.difftime(30, units = "days")) vague_dt(as.difftime(365, units = "days")) vague_dt(as.difftime(365 * 10, units = "days")) ## Short format vague_dt(format = "short", as.difftime(30, units = "secs")) vague_dt(format = "short", as.difftime(14, units = "mins")) vague_dt(format = "short", as.difftime(5, units = "hours")) vague_dt(format = "short", as.difftime(25, units = "hours")) vague_dt(format = "short", as.difftime(5, units = "days")) vague_dt(format = "short", as.difftime(30, units = "days")) vague_dt(format = "short", as.difftime(365, units = "days")) vague_dt(format = "short", as.difftime(365 * 10, units = "days")) ## Even shorter, terse format, (almost always) exactly 3 characters wide vague_dt(format = "terse", as.difftime(30, units = "secs")) vague_dt(format = "terse", as.difftime(14, units = "mins")) vague_dt(format = "terse", as.difftime(5, units = "hours")) vague_dt(format = "terse", as.difftime(25, units = "hours")) vague_dt(format = "terse", as.difftime(5, units = "days")) vague_dt(format = "terse", as.difftime(30, units = "days")) vague_dt(format = "terse", as.difftime(365, units = "days")) vague_dt(format = "terse", as.difftime(365 * 10, units = "days"))