Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
56043c7
commit 548192e
Showing
17 changed files
with
351 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,23 @@ | ||
7f28148db3b2982bde661e8f353cb94e *DESCRIPTION | ||
717550edb9a4c28df3f0c0481db17400 *DESCRIPTION | ||
a07c6138c94c34449bf526709f630608 *LICENSE | ||
f01cc332a8e8806b1996d39ac1fde77b *NAMESPACE | ||
5e8bba1890c7cc91888edd9fafe8678e *NEWS.md | ||
a0d1cf9a23854c6f3c34d203e5c42cb6 *R/assertions.R | ||
2f060416aab46f017e62dd49b0a454f2 *NAMESPACE | ||
1ae1e352545673fc4cb7f318243ff76b *NEWS.md | ||
3dda89562df2d985996bec7279620c5a *R/assertions.R | ||
5a995c67567f66368a439baa2357519c *R/filesize.R | ||
d41d8cd98f00b204e9800998ecf8427e *R/number.R | ||
5a8127f07beb4a90eb2a0bc8882c0aef *R/time.R | ||
27512b890cc625beaa9dd8c7f8e96377 *README.md | ||
f7161b6874a41f2d37469dfe0d8722e4 *R/number.R | ||
0e3b3707c1798c9d5e1341706710a570 *R/time.R | ||
0bb0ddfdb3c4805cbfd4064e07a9a34c *README.md | ||
213f6ce850cc2f6a8536881b43151bd4 *man/count_as_ap.Rd | ||
3e41fbc63d067769d7537b1425c80fec *man/count_as_ordinal.Rd | ||
1ff6e6cf6abc07cbf0f0a9fe5d1fbcb8 *man/count_as_word.Rd | ||
38cb81b0a60f348d403356f1d3ca3c35 *man/natural_date.Rd | ||
f756a05ba9c8f4944b9072a835c1f1ae *man/natural_day.Rd | ||
8a3159ee4c4b4e4f9ca44a7dcf16ad6d *man/natural_day.Rd | ||
a214be85f4f44244d44913af0e229a45 *man/natural_size.Rd | ||
22db532b0cf0b840f093a5ff7a79b43a *man/natural_time.Rd | ||
a10d8ae05a6fe0039b6556d129e4bf32 *man/reexports.Rd | ||
b6b60d56e11b9173238e71296afa85f7 *man/number_as_comma.Rd | ||
76701a869ca8d1ddc56b961f3511f76e *man/reexports.Rd | ||
1953704f71af8288a84faebad83b022f *man/seconds_to_natural_delta.Rd | ||
9ecc77040e0736daad22f876c5462224 *tests/testthat.R | ||
c8a10baee8e6bd53751bf6bd5a938dd4 *tests/testthat/test_filesize.R | ||
56d822a384f68bbfbf18d8996d2e1224 *tests/testthat/test_time.R | ||
e2fe90798dbb22df7c9673fe657a15c0 *tests/testthat/test_filesize.R | ||
4c7c3ceba54f496c6afe7c1df237a2f8 *tests/testthat/test_number.R | ||
fe029a07bb8452670ebe25d80d8e1058 *tests/testthat/test_time.R |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,16 @@ | ||
# Generated by roxygen2: do not edit by hand | ||
|
||
export(count_as_ap) | ||
export(count_as_ordinal) | ||
export(count_as_word) | ||
export(natural_date) | ||
export(natural_day) | ||
export(natural_size) | ||
export(natural_time) | ||
export(number_as_comma) | ||
export(seconds_to_natural_delta) | ||
importFrom(assertthat,assert_that) | ||
importFrom(assertthat,is.count) | ||
importFrom(assertthat,is.date) | ||
importFrom(lubridate,now) | ||
importFrom(lubridate,today) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
|
||
ordinals <- list( | ||
"0" = "th", | ||
"1" = "st", | ||
"2" = "nd", | ||
"3" = "rd", | ||
"4" = "th", | ||
"5" = "th", | ||
"6" = "th", | ||
"7" = "th", | ||
"8" = "th", | ||
"9" = "th" | ||
) | ||
|
||
#' Transform a count to an ordinal string | ||
#' | ||
#' @param value A single positive integer | ||
#' | ||
#' @return A string with the ordinal representation of a number | ||
#' @export | ||
#' | ||
#' @examples | ||
#' count_as_ordinal(1) | ||
#' count_as_ordinal(111) | ||
count_as_ordinal <- function(value) { | ||
assert_that(is.count(value)) | ||
|
||
if (value %% 100 %in% c(11, 12, 13)) { | ||
return(paste0(value, ordinals[["0"]])) | ||
} | ||
paste0(value, ordinals[[as.character(value %% 10)]]) | ||
} | ||
|
||
#' Convert an number to a string with comma separation | ||
#' | ||
#' Just a wrapper around `format` with defaults for full digits | ||
#' | ||
#' @param value A numeric | ||
#' | ||
#' @return A string with comma separation every three digits | ||
#' @export | ||
#' | ||
#' @examples | ||
#' number_as_comma(1000) | ||
#' number_as_comma(10000) | ||
number_as_comma <- function(value) { | ||
assert_that(is.numeric(value)) | ||
format(value, big.mark = ",", scientific = FALSE, digits = 22) | ||
} | ||
|
||
human_powers <- 10^c(6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 100) | ||
names(human_powers) <- c( | ||
'million','billion','trillion','quadrillion', | ||
'quintillion','sextillion','septillion', | ||
'octillion','nonillion','decillion','googol' | ||
) | ||
|
||
#' Convert Large Counts into Friendly Text | ||
#' | ||
#' Note - currently limited to `.Machine$integer.max`. | ||
#' | ||
#' @param value A single positive integer | ||
#' @param fmt Extra number formatting supplied to sprintf | ||
#' | ||
#' @return Returns a string with the power of a number replaced by the appropriate word. | ||
#' @export | ||
#' | ||
#' @examples | ||
#' count_as_word(100) | ||
#' count_as_word(1000000) | ||
#' count_as_word(1200000000) | ||
count_as_word <- function(value, fmt='%.1f') { | ||
assert_that(is.count(value)) | ||
|
||
if (value < human_powers[1]) { | ||
return(format(value, scientific = FALSE)) | ||
} | ||
# Drop the first value, but shift our index | ||
for (i in seq_along(human_powers[-1]) + 1) { | ||
if (value < human_powers[[i]]) { | ||
chopped <- value / human_powers[[i - 1]] | ||
human_name <- names(human_powers[i - 1]) | ||
return(paste(sprintf(fmt, chopped), human_name)) | ||
} | ||
} | ||
# gigantic values | ||
# R does not seem to have percision here. TODO? | ||
return(format(value, scientific = FALSE)) | ||
} | ||
|
||
|
||
ap_numbers <- c("one", "two", "three", "four", "five", "six", "seven", "eight", "nine") | ||
|
||
|
||
#' Convert to AP Number | ||
#' | ||
#' @param value A single positive integer | ||
#' | ||
#' @return For numbers 1-9, returns the number spelled out. Otherwise, returns | ||
#' the number as a string. | ||
#' @export | ||
#' | ||
#' @examples | ||
#' count_as_ap(3) | ||
#' count_as_ap(20) | ||
count_as_ap <- function(value) { | ||
assert_that(is.count(value)) | ||
if (value >= 10) { | ||
return(format(value, scientific = FALSE)) | ||
} | ||
|
||
ap_numbers[value] | ||
} | ||
|
||
fractional <- function(value) { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.