{"id":13857642,"url":"https://github.com/r-lib/prettyunits","last_synced_at":"2025-12-12T01:04:58.242Z","repository":{"id":21453391,"uuid":"24771791","full_name":"r-lib/prettyunits","owner":"r-lib","description":"Pretty, human readable formatting of quantities","archived":false,"fork":false,"pushed_at":"2024-08-05T16:01:51.000Z","size":5044,"stargazers_count":132,"open_issues_count":11,"forks_count":15,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-04-11T13:03:21.898Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://r-lib.github.io/prettyunits/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/r-lib.png","metadata":{"files":{"readme":"README.Rmd","changelog":"NEWS.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-10-03T19:59:19.000Z","updated_at":"2025-03-22T11:23:25.000Z","dependencies_parsed_at":"2024-06-18T21:24:57.976Z","dependency_job_id":"de389b12-891e-4489-aa0d-7a2600f58a56","html_url":"https://github.com/r-lib/prettyunits","commit_stats":{"total_commits":110,"total_committers":5,"mean_commits":22.0,"dds":0.2272727272727273,"last_synced_commit":"e8f45d149c53a3681a95b148997d41a8961b9b8f"},"previous_names":["gaborcsardi/prettyunits"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/r-lib%2Fprettyunits","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/r-lib%2Fprettyunits/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/r-lib%2Fprettyunits/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/r-lib%2Fprettyunits/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/r-lib","download_url":"https://codeload.github.com/r-lib/prettyunits/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248597501,"owners_count":21130889,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-05T03:01:42.826Z","updated_at":"2025-12-12T01:04:53.196Z","avatar_url":"https://github.com/r-lib.png","language":"JavaScript","funding_links":[],"categories":["R","JavaScript"],"sub_categories":[],"readme":"---\noutput: github_document\n---\n\n```{r}\n#| label: setup\n#| echo: false\n#| message: false\nknitr::opts_chunk$set(\n  comment = \"##\u003e\",\n  tidy = FALSE,\n  error = FALSE)\n```\n\n\u003c!-- badges: start --\u003e\n[![R-CMD-check](https://github.com/r-lib/prettyunits/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/r-lib/prettyunits/actions/workflows/R-CMD-check.yaml)\n[![CRAN RStudio mirror downloads](http://cranlogs.r-pkg.org/badges/prettyunits)](https://CRAN.R-project.org/package=prettyunits)\n[![Codecov test coverage](https://codecov.io/gh/r-lib/prettyunits/graph/badge.svg)](https://app.codecov.io/gh/r-lib/prettyunits)\n\u003c!-- badges: end --\u003e\n\n# prettyunits\n\nThe `prettyunits` package formats quantities in human readable form.\n\n* Time intervals: '1337000' -\u003e '15d 11h 23m 20s'.\n* Vague time intervals: '2674000' -\u003e 'about a month ago'.\n* Bytes: '1337' -\u003e '1.34 kB'.\n* Rounding: '99' with 3 significant digits -\u003e '99.0'\n* p-values: '0.00001' -\u003e '\u003c0.0001'.\n* Colors: '#FF0000' -\u003e 'red'.\n* Quantities: '1239437' -\u003e '1.24 M'.\n\n## Installation\n\nYou can install the package from CRAN:\n\n```{r}\n#| eval: false\ninstall.packages(\"prettyunits\")\n```\n\nIf you need the development version, install it from GitHub:\n\n```{r}\n#| eval: false\npak::pak(\"r-lib/prettyunits\")\n```\n\n```{r}\n#| include: false\nlibrary(prettyunits)\nlibrary(magrittr)\n```\n\n## Bytes\n\n`pretty_bytes` formats number of bytes in a human readable way:\n\n```{r}\npretty_bytes(1337)\npretty_bytes(133337)\npretty_bytes(13333337)\npretty_bytes(1333333337)\npretty_bytes(133333333337)\n```\n\nHere is a simple function that emulates the Unix `ls` command, with\nnicely formatted file sizes:\n\n```{r}\nuls \u003c- function(path = \".\") {\n  files \u003c- dir(path)\n  info \u003c- files |\u003e\n    lapply(file.info) |\u003e\n    do.call(what = rbind)\n  info$size \u003c- pretty_bytes(info$size)\n  df \u003c- data.frame(d = ifelse(info$isdir, \"d\", \" \"),\n\tmode = as.character(info$mode), user = info$uname, group = info$grname,\n    size = ifelse(info$isdir, \"\", info$size), modified = info$mtime, name = files)\n  print(df, row.names = FALSE)\n}\nuls()\n```\n\n## Quantities\n\n`pretty_num` formats number related to linear quantities in a human readable way:\n```{r}\npretty_num(1337)\npretty_num(-133337)\npretty_num(1333.37e-9)\n```\nBe aware that the result is wrong in case of surface or volumes, and for any non-linear quantity.\n\nHere is a simple example of how to prettify a entire tibble\n```{r}\nlibrary(tidyverse)\ntdf \u003c- tribble( ~name, ~`size in m`, ~`speed in m/s`,\n                \"land snail\", 0.075, 0.001,\n                \"photon\", NA,  299792458,\n                \"African plate\", 10546330, 0.000000000681)\ntdf |\u003e mutate(across(where(is.numeric), pretty_num))\n```\n\n\n\n## Time intervals\n\n`pretty_ms` formats a time interval given in milliseconds. `pretty_sec` does\nthe same for seconds, and `pretty_dt` for `difftime` objects. The optional\n`compact` argument turns on a compact, approximate format.\n\n```{r}\npretty_ms(c(1337, 13370, 133700, 1337000, 1337000000))\npretty_ms(c(1337, 13370, 133700, 1337000, 1337000000),\n  compact = TRUE)\npretty_sec(c(1337, 13370, 133700, 1337000, 13370000))\npretty_sec(c(1337, 13370, 133700, 1337000, 13370000),\n  compact = TRUE)\n\n```\n\n## Vague time intervals\n\n`vague_dt` and `time_ago` formats time intervals using a vague format,\nomitting smaller units. They both have three formats: `default`, `short` and `terse`.\n`vague_dt` takes a `difftime` object, and `time_ago` works relatively to the\nspecified date.\n\n```{r}\nvague_dt(format = \"short\", as.difftime(30, units = \"secs\"))\nvague_dt(format = \"short\", as.difftime(14, units = \"mins\"))\nvague_dt(format = \"short\", as.difftime(5, units = \"hours\"))\nvague_dt(format = \"short\", as.difftime(25, units = \"hours\"))\nvague_dt(format = \"short\", as.difftime(5, units = \"days\"))\n```\n\n```{r}\nnow \u003c- Sys.time()\ntime_ago(now)\ntime_ago(now - as.difftime(30, units = \"secs\"))\ntime_ago(now - as.difftime(14, units = \"mins\"))\ntime_ago(now - as.difftime(5, units = \"hours\"))\ntime_ago(now - as.difftime(25, units = \"hours\"))\n```\n\n## Rounding\n\n`pretty_round()` and `pretty_signif()` preserve trailing zeros.\n\n```{r}\npretty_round(1, digits=6)\npretty_signif(c(99, 0.9999), digits=3)\n```\n\n## p-values\n\n`pretty_p_value()` rounds small p-values to indicate less than significance\nlevel for small values.\n\n```{r}\npretty_p_value(c(0.05, 0.0000001, NA))\n```\n\n## Colors\n\n`pretty_color` converts colors from other representations to human-readable\nnames.\n\n```{r}\npretty_color(\"black\")\npretty_color(\"#123456\")\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fr-lib%2Fprettyunits","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fr-lib%2Fprettyunits","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fr-lib%2Fprettyunits/lists"}