/usr/lib/R/site-library/prettyunits/README.md is in r-cran-prettyunits 1.0.2-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | [](https://travis-ci.org/gaborcsardi/prettyunits)
[](https://ci.appveyor.com/project/gaborcsardi/prettyunits)
[](http://cran.r-project.org/web/packages/prettyunits/index.html)
# prettyunits
The `prettyunits` package formats quantities in human readable form. Currently
time units and information (i.e. bytes) are supported.
## Installation
You can install the package from github:
```r
library(devtools)
install_github("gaborcsardi/prettyunits")
```
```r
library(prettyunits)
library(magrittr)
```
## Bytes
`pretty_bytes` formats number of bytes in a human readable way:
```r
pretty_bytes(1337)
```
```
##> [1] "1.34 kB"
```
```r
pretty_bytes(133337)
```
```
##> [1] "133.34 kB"
```
```r
pretty_bytes(13333337)
```
```
##> [1] "13.33 MB"
```
```r
pretty_bytes(1333333337)
```
```
##> [1] "1.33 GB"
```
```r
pretty_bytes(133333333337)
```
```
##> [1] "133.33 GB"
```
Here is a simple function that emulates the Unix `ls` command, with
nicely formatted file sizes:
```r
uls <- function(path = ".") {
files <- dir(path)
info <- files %>%
lapply(file.info) %>%
do.call(what = rbind)
info$size <- pretty_bytes(info$size)
df <- data.frame(d = ifelse(info$isdir, "d", " "),
mode = as.character(info$mode), user = info$uname, group = info$grname,
size = ifelse(info$isdir, "", info$size), modified = info$mtime, name = files)
print(df, row.names = FALSE)
}
uls()
```
```
##> d mode user group size modified name
##> 644 gaborcsardi staff 795.00 B 2014-10-13 09:00:43 appveyor.yml
##> 644 gaborcsardi staff 561.00 B 2014-10-13 09:19:59 DESCRIPTION
##> 644 gaborcsardi staff 42.00 B 2014-10-03 15:44:54 LICENSE
##> 644 gaborcsardi staff 111.00 B 2014-10-12 23:07:32 Makefile
##> d 755 gaborcsardi staff 2014-10-12 16:51:06 man
##> 644 gaborcsardi staff 259.00 B 2014-10-12 16:51:39 NAMESPACE
##> d 755 gaborcsardi staff 2014-10-12 16:47:25 R
##> 644 gaborcsardi staff 4.46 kB 2014-10-13 09:04:42 README.md
##> 644 gaborcsardi staff 2.98 kB 2015-04-23 15:18:17 README.Rmd
##> 644 gaborcsardi staff 4.01 kB 2015-03-14 14:42:48 tags
##> d 755 gaborcsardi staff 2014-10-12 15:15:48 tests
```
## Time intervals
`pretty_ms` formats a time interval given in milliseconds. `pretty_sec` does
the same for seconds, and `pretty_dt` for `difftime` objects. The optional
`compact` argument turns on a compact, approximate format.
```r
pretty_ms(c(1337, 13370, 133700, 1337000, 1337000000))
```
```
##> [1] "1.3s" "13.4s" "2m 13.7s" "22m 17s"
##> [5] "15d 11h 23m 20s"
```
```r
pretty_ms(c(1337, 13370, 133700, 1337000, 1337000000),
compact = TRUE)
```
```
##> [1] "~1.3s" "~13.4s" "~2m" "~22m" "~15d"
```
```r
pretty_sec(c(1337, 13370, 133700, 1337000, 13370000))
```
```
##> [1] "22m 17s" "3h 42m 50s" "1d 13h 8m 20s"
##> [4] "15d 11h 23m 20s" "154d 17h 53m 20s"
```
```r
pretty_sec(c(1337, 13370, 133700, 1337000, 13370000),
compact = TRUE)
```
```
##> [1] "~22m" "~3h" "~1d" "~15d" "~154d"
```
## Vague time intervals
`vague_dt` and `time_ago` formats time intervals using a vague format,
omitting smaller units. They both have three formats: `default`, `short` and `terse`.
`vague_dt` takes a `difftime` object, and `time_ago` works relatively to the
specified date.
```r
vague_dt(format = "short", as.difftime(30, units = "secs"))
```
```
##> [1] "<1 min"
```
```r
vague_dt(format = "short", as.difftime(14, units = "mins"))
```
```
##> [1] "14 min"
```
```r
vague_dt(format = "short", as.difftime(5, units = "hours"))
```
```
##> [1] "5 hours"
```
```r
vague_dt(format = "short", as.difftime(25, units = "hours"))
```
```
##> [1] "1 day"
```
```r
vague_dt(format = "short", as.difftime(5, units = "days"))
```
```
##> [1] "5 day"
```
```r
now <- Sys.time()
time_ago(now)
```
```
##> [1] "moments ago"
```
```r
time_ago(now - as.difftime(30, units = "secs"))
```
```
##> [1] "less than a minute ago"
```
```r
time_ago(now - as.difftime(14, units = "mins"))
```
```
##> [1] "14 minutes ago"
```
```r
time_ago(now - as.difftime(5, units = "hours"))
```
```
##> [1] "5 hours ago"
```
```r
time_ago(now - as.difftime(25, units = "hours"))
```
```
##> [1] "a day ago"
```
|