Title: | Pretty, Human Readable Formatting of Quantities |
Version: | 1.2.0 |
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'. |
License: | MIT + file LICENSE |
URL: | https://github.com/r-lib/prettyunits |
BugReports: | https://github.com/r-lib/prettyunits/issues |
Depends: | R(≥ 2.10) |
Suggests: | codetools, covr, testthat |
RoxygenNote: | 7.2.3 |
Encoding: | UTF-8 |
NeedsCompilation: | no |
Packaged: | 2023-09-24 10:53:19 UTC; gaborcsardi |
Author: | Gabor Csardi [aut, cre],
Bill Denney |
Maintainer: | Gabor Csardi <csardi.gabor@gmail.com> |
Repository: | CRAN |
Date/Publication: | 2023-09-24 21:10:02 UTC |
Prettier formatting of quantities
Description
Render quantities with a pretty, human-readable formatting.
Time intervals: '1337000' -> '15d 11h 23m 20s'.
Vague time intervals: '2674000' -> 'about a month ago'.
Bytes: '1337' -> '1.34 kB'.
p-values: '0.00001' -> '<0.0001'.
Colors: '#FF0000' -> 'red'.
Quantities: '1239437' -> '1.24 M'.
Author(s)
Maintainer: Gabor Csardi csardi.gabor@gmail.com
Other contributors:
Bill Denney wdenney@humanpredictions.com (ORCID) [contributor]
Christophe Regouby christophe.regouby@free.fr [contributor]
See Also
Useful links:
Color names, hexadecimal, and CIE Lab colorspace representations
Description
- hex
hexadecimal color representation (without the # at the beginning)
- L,a,b
CIE Lab colorspace representation of
hex
- name
Preferred human-readable name of the color
- name_alt
All available human-readable names of the color
- roygbiv,basic,html,R,pantone,x11,ntc
Source dataset containing the color
Source
https://github.com/colorjs/color-namer and R colors()
Bytes in a human readable string
Description
Use pretty_bytes()
to format bytes. compute_bytes()
is the underlying
engine that may be useful for custom formatting.
Usage
pretty_bytes(bytes, style = c("default", "nopad", "6"))
compute_bytes(bytes, smallest_unit = "B")
Arguments
bytes |
Numeric vector, number of bytes. |
style |
Formatting style:
|
smallest_unit |
A character scalar, the smallest unit to use. |
Value
Character vector, the formatted sizes.
For compute_bytes
, a data frame with columns amount
, unit
,
negative
.
Examples
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
Description
Color definition (like RGB) to a name
Usage
pretty_color(color)
pretty_colour(color)
Arguments
color |
A scalar color that is usable as an input to |
Value
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)
Description
Pretty formatting of time intervals (difftime objects)
Usage
pretty_dt(dt, compact = FALSE)
Arguments
dt |
A |
compact |
If true, then only the first non-zero unit is used. See examples below. |
Value
Character vector of formatted time intervals.
See Also
Other time:
pretty_ms()
,
pretty_sec()
Examples
pretty_dt(as.difftime(1000, units = "secs"))
pretty_dt(as.difftime(0, units = "secs"))
Pretty formatting of milliseconds
Description
Pretty formatting of milliseconds
Usage
pretty_ms(ms, compact = FALSE)
Arguments
ms |
Numeric vector of milliseconds |
compact |
If true, then only the first non-zero unit is used. See examples below. |
Value
Character vector of formatted time intervals.
See Also
Other time:
pretty_dt()
,
pretty_sec()
Examples
pretty_ms(c(1337, 13370, 133700, 1337000, 1337000000))
pretty_ms(c(1337, 13370, 133700, 1337000, 1337000000),
compact = TRUE)
Linear quantities in a human readable string
Description
Use pretty_num()
to format numbers compute_num()
is the underlying
engine that may be useful for custom formatting.
Usage
pretty_num(number, style = c("default", "nopad", "6"))
compute_num(number, smallest_prefix = "y")
Arguments
number |
Numeric vector, number related to a linear quantity. |
style |
Formatting style:
|
smallest_prefix |
A character scalar, the smallest prefix to use. |
Value
Character vector, the formatted sizes.
For compute_num
, a data frame with columns amount
, prefix
,
negative
.
Examples
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
Description
p-values in a human-readable string
Usage
pretty_p_value(x, minval = 1e-04)
Arguments
x |
A numeric vector. |
minval |
The minimum p-value to show (lower values will show as
|
Value
A character vector of p-value representations.
Examples
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
Description
Round a value to a defined number of digits printing out trailing zeros, if applicable
Usage
pretty_round(x, digits = 0, sci_range = Inf, sci_sep = "e")
Arguments
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). |
Details
Values that are not standard numbers like Inf
, NA
, and
NaN
are returned as "Inf"
, "NA"
, and "NaN"
.
Value
A string with the value.
See Also
Pretty formatting of seconds
Description
Pretty formatting of seconds
Usage
pretty_sec(sec, compact = FALSE)
Arguments
sec |
Numeric vector of seconds. |
compact |
If true, then only the first non-zero unit is used. See examples below. |
Value
Character vector of formatted time intervals.
See Also
Other time:
pretty_dt()
,
pretty_ms()
Examples
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
Description
Round a value to a defined number of significant digits printing out trailing zeros, if applicable
Usage
pretty_signif(x, digits = 6, sci_range = 6, sci_sep = "e")
Arguments
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). |
Details
Values that are not standard numbers like Inf
, NA
, and
NaN
are returned as "Inf"
, "NA"
, and NaN
.
Value
A string with the value.
See Also
Human readable format of the time interval since a time point
Description
It calls vague_dt
to do the actual formatting.
Usage
time_ago(date, format = c("default", "short", "terse"))
Arguments
date |
Date(s), |
format |
Format, currently available formats are: ‘default’, ‘short’, ‘terse’. See examples below. |
Value
Character vector of the formatted time intervals.
Examples
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
Description
Human readable format of a time interval
Usage
vague_dt(dt, format = c("default", "short", "terse"))
Arguments
dt |
A |
format |
Format, currently available formats are: ‘default’, ‘short’, ‘terse’. See examples below. |
Value
Character vector of the formatted time intervals.
Examples
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"))