Create Values for Human Consumption

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.


Travis-CI Build Status CRAN_Status_Badge

Humanize is an almost direct port of the python humanize package.

The goal of humanize is to provide some utlities in order to turn values (so far times, file sizes, and numbers) into human readable forms.

Installation

You can install the latest CRAN version with:

install.packages("humanize")

You can install humanize from github with:

devtools::install_github("newtux/humanize")

Examples

Times

Convert times:

library(humanize)
 
natural_time(Sys.time())
#> [1] "now"
natural_time(Sys.time() - 1)
#> [1] "a second ago"
natural_time(Sys.time() - 100)
#> [1] "a minute ago"
natural_time(Sys.time() - 1000*10)
#> [1] "2 hours ago"

Works across days:

natural_time(Sys.time() - lubridate::ddays(1))
#> [1] "a day ago"
natural_time(Sys.time() - lubridate::ddays(70))
#> [1] "2 months ago"

And forward in time:

natural_time(Sys.time() + lubridate::ddays(1))
#> [1] "23 hours from now"

File Sizes

Convert file sizes:

natural_size(300)
#> 300 Bytes
natural_size(3000)
#> 3.0 kB
natural_size(3000000)
#> 3.0 MB
natural_size(3000000000)
#> 3.0 GB
natural_size(3000000000000)
#> 3.0 TB
natural_size(10**26 * 30)
#> 3000.0 YB

Numbers

Ordinals:

count_as_ordinal(1)
#> [1] "1st"
count_as_ordinal(111)
#> [1] "111th"

Comma Seperation:

number_as_comma(1000)
#> [1] "1,000"
number_as_comma(10000)
#> [1] "10,000"

Words:

count_as_word(100)
#> [1] "100"
count_as_word(1000000)
#> [1] "1.0 million"
count_as_word(1200000000)
#> [1] "1.2 billion"

AP Format:

count_as_ap(3)
#> [1] "three"
count_as_ap(20)
#> [1] "20"

Todo

This is still a very early cut of the package.

  • Better support in times? For diff time?
  • Maybe add times relative to other times?
  • Export helper functions used in tests?

News

humanize 0.2.0

  • Ported over number functions
  • Clean up arguments to be consistent across library (format -> fmt)
  • Fix bugs with tests

humanize 0.1.0

  • Ported over time functions
  • Ported over filesize functions
  • Added a NEWS.md file to track changes to the package.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("humanize")

0.2.0 by Gerry Manoim, a year ago


https://newtux.github.io/humanize/index.html, https://github.com/newtux/humanize


Report a bug at https://github.com/newtux/humanize/issues


Browse source code at https://github.com/cran/humanize


Authors: Gerry Manoim [aut, cre]


Documentation:   PDF Manual  


MIT + file LICENSE license


Imports lubridate, assertthat, glue

Suggests testthat, purrr


See at CRAN