MyNixOS website logo
Description

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.

humanize

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:

# install.packages("devtools")
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?
Metadata

Version

0.2.0

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows