From 6b3167588381c35685d67438c9952afb73de1ab6 Mon Sep 17 00:00:00 2001 From: ZAYED Date: Thu, 3 Oct 2024 11:55:06 +0100 Subject: [PATCH 1/9] added nsmall args to pretty_num and comma_sep to allow formatting of decimals --- R/comma_sep.R | 5 +++-- R/pretty.R | 47 +++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 46 insertions(+), 6 deletions(-) diff --git a/R/comma_sep.R b/R/comma_sep.R index f34176f..5653953 100644 --- a/R/comma_sep.R +++ b/R/comma_sep.R @@ -13,6 +13,7 @@ #' comma_sep(100) #' comma_sep(1000) #' comma_sep(3567000) -comma_sep <- function(number) { - format(number, big.mark = ",", trim = TRUE, scientific = FALSE) +comma_sep <- function(number, + nsmall = 0L) { + format(number, big.mark = ",", nsmall=nsmall, trim = TRUE, scientific = FALSE) } diff --git a/R/pretty.R b/R/pretty.R index ba848d1..f5f2b33 100644 --- a/R/pretty.R +++ b/R/pretty.R @@ -188,6 +188,7 @@ pretty_time_taken <- function(start_time, end_time) { #' @param ignore_na whether to skip function for strings that can't be #' converted and return original value #' @param alt_na alternative value to return in place of NA, e.g. "x" +#' @param nsmall minimum number of digits to the right of the decimal point #' #' @return string featuring prettified value #' @family prettying @@ -223,7 +224,8 @@ pretty_num <- function( suffix = "", dp = 2, ignore_na = FALSE, - alt_na = FALSE) { + alt_na = FALSE, + nsmall = NULL) { # Check we're only trying to prettify a single value if (length(value) > 1) { stop("value must be a single value, multiple values were detected") @@ -263,11 +265,47 @@ pretty_num <- function( } # Add suffix and prefix, plus convert to million or billion + + # If nsmall is not given, make same value as dp + + if(is.null(nsmall)){ + + nsmall <- dp + + if (abs(num_value) >= 1.e9) { + paste0( + prefix, + currency, + comma_sep(round_five_up(abs(num_value) / 1.e9, dp = dp), nsmall = nsmall), + " billion", + suffix + ) + } else if (abs(num_value) >= 1.e6) { + paste0( + prefix, + currency, + comma_sep(round_five_up(abs(num_value) / 1.e6, dp = dp), nsmall = nsmall), + " million", + suffix + ) + } else { + paste0( + prefix, + currency, + comma_sep(round_five_up(abs(num_value), dp = dp), nsmall = nsmall), + suffix + ) + } + + }else { + + # If nsmall is given, use that value + if (abs(num_value) >= 1.e9) { paste0( prefix, currency, - comma_sep(round_five_up(abs(num_value) / 1.e9, dp = dp)), + comma_sep(round_five_up(abs(num_value) / 1.e9, dp = dp), nsmall = nsmall), " billion", suffix ) @@ -275,7 +313,7 @@ pretty_num <- function( paste0( prefix, currency, - comma_sep(round_five_up(abs(num_value) / 1.e6, dp = dp)), + comma_sep(round_five_up(abs(num_value) / 1.e6, dp = dp), nsmall = nsmall), " million", suffix ) @@ -283,8 +321,9 @@ pretty_num <- function( paste0( prefix, currency, - comma_sep(round_five_up(abs(num_value), dp = dp)), + comma_sep(round_five_up(abs(num_value), dp = dp), nsmall = nsmall), suffix ) } } +} From 6f38c67ec4dde6b18bc5f4d4e6f02868c19158a8 Mon Sep 17 00:00:00 2001 From: ZAYED Date: Fri, 4 Oct 2024 09:47:56 +0100 Subject: [PATCH 2/9] amended the function so it takes multiple values --- R/pretty.R | 175 +++++++++++++++++++++++++++-------------------------- 1 file changed, 90 insertions(+), 85 deletions(-) diff --git a/R/pretty.R b/R/pretty.R index f5f2b33..9887538 100644 --- a/R/pretty.R +++ b/R/pretty.R @@ -226,104 +226,109 @@ pretty_num <- function( ignore_na = FALSE, alt_na = FALSE, nsmall = NULL) { - # Check we're only trying to prettify a single value - if (length(value) > 1) { - stop("value must be a single value, multiple values were detected") - } - # Force to numeric - num_value <- suppressWarnings(as.numeric(value)) + #use lapply to use the function for singular value or a vector - # Check if should skip function - if (is.na(num_value)) { - if (ignore_na == TRUE) { - return(value) # return original value - } else if (alt_na != FALSE) { - return(alt_na) # return custom NA value - } else { - return(num_value) # return NA - } - } + result <- lapply(value, function(value){ + # Force to numeric + num_value <- suppressWarnings(as.numeric(value)) - # Convert GBP to pound symbol - if (gbp == TRUE) { - currency <- "\U00a3" - } else { - currency <- "" - } + # Check if should skip function + if (is.na(num_value)) { + if (ignore_na == TRUE) { + return(value) # return original value + } else if (alt_na != FALSE) { + return(alt_na) # return custom NA value + } else { + return(num_value) # return NA + } + } - # Add + / - symbols depending on size of value - if (prefix == "+/-") { - if (value >= 0) { - prefix <- "+" + # Convert GBP to pound symbol + if (gbp == TRUE) { + currency <- "\U00a3" } else { - prefix <- "-" + currency <- "" } - # Add in negative symbol if appropriate and not auto added with +/- - } else if (value < 0) { - prefix <- paste0("-", prefix) - } - # Add suffix and prefix, plus convert to million or billion + # Add + / - symbols depending on size of value + if (prefix == "+/-") { + if (value >= 0) { + prefix <- "+" + } else { + prefix <- "-" + } + # Add in negative symbol if appropriate and not auto added with +/- + } else if (value < 0) { + prefix <- paste0("-", prefix) + } - # If nsmall is not given, make same value as dp + # Add suffix and prefix, plus convert to million or billion - if(is.null(nsmall)){ + # If nsmall is not given, make same value as dp - nsmall <- dp + if(is.null(nsmall)){ - if (abs(num_value) >= 1.e9) { - paste0( - prefix, - currency, - comma_sep(round_five_up(abs(num_value) / 1.e9, dp = dp), nsmall = nsmall), - " billion", - suffix - ) - } else if (abs(num_value) >= 1.e6) { - paste0( - prefix, - currency, - comma_sep(round_five_up(abs(num_value) / 1.e6, dp = dp), nsmall = nsmall), - " million", - suffix - ) - } else { - paste0( - prefix, - currency, - comma_sep(round_five_up(abs(num_value), dp = dp), nsmall = nsmall), - suffix - ) - } + nsmall <- dp + + if (abs(num_value) >= 1.e9) { + paste0( + prefix, + currency, + comma_sep(round_five_up(abs(num_value) / 1.e9, dp = dp), nsmall = nsmall), + " billion", + suffix + ) + } else if (abs(num_value) >= 1.e6) { + paste0( + prefix, + currency, + comma_sep(round_five_up(abs(num_value) / 1.e6, dp = dp), nsmall = nsmall), + " million", + suffix + ) + } else { + paste0( + prefix, + currency, + comma_sep(round_five_up(abs(num_value), dp = dp), nsmall = nsmall), + suffix + ) + } - }else { + }else { - # If nsmall is given, use that value + # If nsmall is given, use that value + + if (abs(num_value) >= 1.e9) { + paste0( + prefix, + currency, + comma_sep(round_five_up(abs(num_value) / 1.e9, dp = dp), nsmall = nsmall), + " billion", + suffix + ) + } else if (abs(num_value) >= 1.e6) { + paste0( + prefix, + currency, + comma_sep(round_five_up(abs(num_value) / 1.e6, dp = dp), nsmall = nsmall), + " million", + suffix + ) + } else { + paste0( + prefix, + currency, + comma_sep(round_five_up(abs(num_value), dp = dp), nsmall = nsmall), + suffix + ) + } + } - if (abs(num_value) >= 1.e9) { - paste0( - prefix, - currency, - comma_sep(round_five_up(abs(num_value) / 1.e9, dp = dp), nsmall = nsmall), - " billion", - suffix - ) - } else if (abs(num_value) >= 1.e6) { - paste0( - prefix, - currency, - comma_sep(round_five_up(abs(num_value) / 1.e6, dp = dp), nsmall = nsmall), - " million", - suffix - ) - } else { - paste0( - prefix, - currency, - comma_sep(round_five_up(abs(num_value), dp = dp), nsmall = nsmall), - suffix - ) } -} + )#lapply bracket + + #unlisting the results so that they're all on one line + return(unlist(result)) } From 9753670af1435ae64a9c25b11010c5fa7c001144 Mon Sep 17 00:00:00 2001 From: ZAYED Date: Fri, 4 Oct 2024 11:56:17 +0100 Subject: [PATCH 3/9] updated documenation --- R/pretty.R | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/R/pretty.R b/R/pretty.R index 9887538..963da35 100644 --- a/R/pretty.R +++ b/R/pretty.R @@ -209,14 +209,15 @@ pretty_time_taken <- function(start_time, end_time) { #' #' # Applied over an example vector #' vector <- c(3998098008, -123421421, "c", "x") -#' unlist(lapply(vector, pretty_num)) -#' unlist(lapply(vector, pretty_num, prefix = "+/-", gbp = TRUE)) +#' pretty_num(vector) +#' pretty_num(vector, prefix = "+/-", gbp = TRUE) #' #' # Return original values if NA -#' unlist(lapply(vector, pretty_num, ignore_na = TRUE)) +#' pretty_num(vector,ignore_na = TRUE) #' #' # Return alternative value in place of NA -#' unlist(lapply(vector, pretty_num, alt_na = "z")) +#' pretty_num(vector, alt_na = "z") + pretty_num <- function( value, prefix = "", From c30d2510df16292c5cd3a08059c80a928504ba0e Mon Sep 17 00:00:00 2001 From: ZAYED Date: Mon, 7 Oct 2024 12:08:28 +0100 Subject: [PATCH 4/9] fixed the issue with negative dp being passed to nsmall --- R/pretty.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/pretty.R b/R/pretty.R index 963da35..5751bc3 100644 --- a/R/pretty.R +++ b/R/pretty.R @@ -270,7 +270,7 @@ pretty_num <- function( if(is.null(nsmall)){ - nsmall <- dp + nsmall <- abs(dp) if (abs(num_value) >= 1.e9) { paste0( From c5f952bf6c4e50b551a1d60892a8d7580835044f Mon Sep 17 00:00:00 2001 From: ZAYED Date: Mon, 7 Oct 2024 13:14:47 +0100 Subject: [PATCH 5/9] changed code for testing pretty_num --- tests/testthat/test-pretty_num.R | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/testthat/test-pretty_num.R b/tests/testthat/test-pretty_num.R index 2cf3180..40908ee 100644 --- a/tests/testthat/test-pretty_num.R +++ b/tests/testthat/test-pretty_num.R @@ -1,17 +1,17 @@ test_that("prettifies", { - expect_equal(pretty_num(1, gbp = TRUE, suffix = " offer"), "£1 offer") - expect_equal(pretty_num(-1), "-1") - expect_equal(pretty_num(-1, prefix = "-"), "--1") - expect_equal(pretty_num(-1, prefix = "+/-"), "-1") - expect_equal(pretty_num(1, prefix = "+/-"), "+1") + expect_equal(pretty_num(1, gbp = TRUE, suffix = " offer"), "£1.00 offer") + expect_equal(pretty_num(-1), "-1.00") + expect_equal(pretty_num(-1, prefix = "-"), "--1.00") + expect_equal(pretty_num(-1, prefix = "+/-"), "-1.00") + expect_equal(pretty_num(1, prefix = "+/-"), "+1.00") expect_equal(pretty_num(12.289009, suffix = "%"), "12.29%") - expect_equal(pretty_num(1000), "1,000") - expect_equal(pretty_num(11^8, gbp = TRUE, dp = -1), "£210 million") + expect_equal(pretty_num(1000), "1,000.00") + expect_equal(pretty_num(11^8, gbp = TRUE, dp = -1), "£210.0 million") expect_equal(pretty_num(11^9, gbp = TRUE, dp = 3), "£2.358 billion") - expect_equal(pretty_num(-11^8, gbp = TRUE, dp = -1), "-£210 million") + expect_equal(pretty_num(-11^8, gbp = TRUE, dp = -1), "-£210.0 million") expect_equal(pretty_num(-123421421), "-123.42 million") expect_equal( - pretty_num(11^8, prefix = "+/-", gbp = TRUE, dp = -1), "+£210 million" + pretty_num(11^8, prefix = "+/-", gbp = TRUE, dp = -1.00), "+£210.0 million" ) }) @@ -22,9 +22,9 @@ test_that("handles NAs", { expect_equal(pretty_num("x", alt_na = "c"), "c") }) -test_that("rejects multiple values", { +test_that("tests multiple values", { expect_error( pretty_num(c(1:4)), - "value must be a single value, multiple values were detected" + c("1.00" ,"2.00", "3.00" ,"4.00") ) }) From bf75fc99875b9805d84323216bc2783051ce4c90 Mon Sep 17 00:00:00 2001 From: ZAYED Date: Mon, 7 Oct 2024 13:24:30 +0100 Subject: [PATCH 6/9] amended the documentation for comma_sep and changed expected_error to expect_equal in test_pretty_num --- R/comma_sep.R | 1 + tests/testthat/test-pretty_num.R | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/R/comma_sep.R b/R/comma_sep.R index 5653953..37cb40c 100644 --- a/R/comma_sep.R +++ b/R/comma_sep.R @@ -5,6 +5,7 @@ #' return the value unchanged and as a string. #' #' @param number number to be comma separated +#' @param nsmall minimum number of digits to the right of the decimal point #' #' @return string #' @export diff --git a/tests/testthat/test-pretty_num.R b/tests/testthat/test-pretty_num.R index 40908ee..9a653ec 100644 --- a/tests/testthat/test-pretty_num.R +++ b/tests/testthat/test-pretty_num.R @@ -23,7 +23,7 @@ test_that("handles NAs", { }) test_that("tests multiple values", { - expect_error( + expect_equal( pretty_num(c(1:4)), c("1.00" ,"2.00", "3.00" ,"4.00") ) From 4556241e71d11d433105195f42222a0b4621ecd7 Mon Sep 17 00:00:00 2001 From: ZAYED Date: Mon, 7 Oct 2024 16:47:30 +0100 Subject: [PATCH 7/9] fixed the - dp args problem added nsmall to the documentation fixed the lintr styling and complexity errors --- R/comma_sep.R | 5 +- R/pretty.R | 107 +++++++++++++------------------ man/comma_sep.Rd | 4 +- man/pretty_num.Rd | 13 ++-- tests/testthat/test-pretty_num.R | 2 +- 5 files changed, 59 insertions(+), 72 deletions(-) diff --git a/R/comma_sep.R b/R/comma_sep.R index 37cb40c..fbb7758 100644 --- a/R/comma_sep.R +++ b/R/comma_sep.R @@ -16,5 +16,8 @@ #' comma_sep(3567000) comma_sep <- function(number, nsmall = 0L) { - format(number, big.mark = ",", nsmall=nsmall, trim = TRUE, scientific = FALSE) + format(number, + big.mark = ",", nsmall = nsmall, trim = TRUE, + scientific = FALSE + ) } diff --git a/R/pretty.R b/R/pretty.R index 5751bc3..a9704d2 100644 --- a/R/pretty.R +++ b/R/pretty.R @@ -213,11 +213,10 @@ pretty_time_taken <- function(start_time, end_time) { #' pretty_num(vector, prefix = "+/-", gbp = TRUE) #' #' # Return original values if NA -#' pretty_num(vector,ignore_na = TRUE) +#' pretty_num(vector, ignore_na = TRUE) #' #' # Return alternative value in place of NA #' pretty_num(vector, alt_na = "z") - pretty_num <- function( value, prefix = "", @@ -227,10 +226,9 @@ pretty_num <- function( ignore_na = FALSE, alt_na = FALSE, nsmall = NULL) { + # use lapply to use the function for singular value or a vector - #use lapply to use the function for singular value or a vector - - result <- lapply(value, function(value){ + result <- lapply(value, function(value) { # Force to numeric num_value <- suppressWarnings(as.numeric(value)) @@ -267,69 +265,50 @@ pretty_num <- function( # Add suffix and prefix, plus convert to million or billion # If nsmall is not given, make same value as dp + # if dp is smaller than 0, make nsmall 0 + # if nsmall is specified, use that value - if(is.null(nsmall)){ - - nsmall <- abs(dp) - - if (abs(num_value) >= 1.e9) { - paste0( - prefix, - currency, - comma_sep(round_five_up(abs(num_value) / 1.e9, dp = dp), nsmall = nsmall), - " billion", - suffix - ) - } else if (abs(num_value) >= 1.e6) { - paste0( - prefix, - currency, - comma_sep(round_five_up(abs(num_value) / 1.e6, dp = dp), nsmall = nsmall), - " million", - suffix - ) - } else { - paste0( - prefix, - currency, - comma_sep(round_five_up(abs(num_value), dp = dp), nsmall = nsmall), - suffix - ) - } - - }else { + if (!is.null(nsmall)) { + nsmall <- nsmall + } else if (dp > 0 & is.null(nsmall)) { + nsmall <- dp + } else { + nsmall <- 0 + } - # If nsmall is given, use that value - if (abs(num_value) >= 1.e9) { - paste0( - prefix, - currency, - comma_sep(round_five_up(abs(num_value) / 1.e9, dp = dp), nsmall = nsmall), - " billion", - suffix - ) - } else if (abs(num_value) >= 1.e6) { - paste0( - prefix, - currency, - comma_sep(round_five_up(abs(num_value) / 1.e6, dp = dp), nsmall = nsmall), - " million", - suffix - ) - } else { - paste0( - prefix, - currency, - comma_sep(round_five_up(abs(num_value), dp = dp), nsmall = nsmall), - suffix - ) - } + if (abs(num_value) >= 1.e9) { + paste0( + prefix, + currency, + comma_sep(round_five_up(abs(num_value) / 1.e9, dp = dp), + nsmall = nsmall + ), + " billion", + suffix + ) + } else if (abs(num_value) >= 1.e6) { + paste0( + prefix, + currency, + comma_sep(round_five_up(abs(num_value) / 1.e6, dp = dp), + nsmall = nsmall + ), + " million", + suffix + ) + } else { + paste0( + prefix, + currency, + comma_sep(round_five_up(abs(num_value), dp = dp), + nsmall = nsmall + ), + suffix + ) } + }) # lapply bracket - } - )#lapply bracket - - #unlisting the results so that they're all on one line + # unlisting the results so that they're all on one line return(unlist(result)) } diff --git a/man/comma_sep.Rd b/man/comma_sep.Rd index d321a72..f2092f3 100644 --- a/man/comma_sep.Rd +++ b/man/comma_sep.Rd @@ -4,10 +4,12 @@ \alias{comma_sep} \title{Comma separate} \usage{ -comma_sep(number) +comma_sep(number, nsmall = 0L) } \arguments{ \item{number}{number to be comma separated} + +\item{nsmall}{minimum number of digits to the right of the decimal point} } \value{ string diff --git a/man/pretty_num.Rd b/man/pretty_num.Rd index aaeff8e..4436e75 100644 --- a/man/pretty_num.Rd +++ b/man/pretty_num.Rd @@ -11,7 +11,8 @@ pretty_num( suffix = "", dp = 2, ignore_na = FALSE, - alt_na = FALSE + alt_na = FALSE, + nsmall = NULL ) } \arguments{ @@ -30,6 +31,8 @@ assign + or - based on the value} converted and return original value} \item{alt_na}{alternative value to return in place of NA, e.g. "x"} + +\item{nsmall}{minimum number of digits to the right of the decimal point} } \value{ string featuring prettified value @@ -66,14 +69,14 @@ pretty_num("nope", alt_na = "x") # Applied over an example vector vector <- c(3998098008, -123421421, "c", "x") -unlist(lapply(vector, pretty_num)) -unlist(lapply(vector, pretty_num, prefix = "+/-", gbp = TRUE)) +pretty_num(vector) +pretty_num(vector, prefix = "+/-", gbp = TRUE) # Return original values if NA -unlist(lapply(vector, pretty_num, ignore_na = TRUE)) +pretty_num(vector,ignore_na = TRUE) # Return alternative value in place of NA -unlist(lapply(vector, pretty_num, alt_na = "z")) +pretty_num(vector, alt_na = "z") } \seealso{ \code{\link[=comma_sep]{comma_sep()}} \code{\link[=round_five_up]{round_five_up()}} \code{\link[=as.numeric]{as.numeric()}} diff --git a/tests/testthat/test-pretty_num.R b/tests/testthat/test-pretty_num.R index 9a653ec..95a9e61 100644 --- a/tests/testthat/test-pretty_num.R +++ b/tests/testthat/test-pretty_num.R @@ -25,6 +25,6 @@ test_that("handles NAs", { test_that("tests multiple values", { expect_equal( pretty_num(c(1:4)), - c("1.00" ,"2.00", "3.00" ,"4.00") + c("1.00", "2.00", "3.00", "4.00") ) }) From a23bf8728ea0126b2bd8da87d38a57636327076b Mon Sep 17 00:00:00 2001 From: ZAYED Date: Mon, 7 Oct 2024 16:55:25 +0100 Subject: [PATCH 8/9] added extra tests to pretty_num --- R/pretty.R | 1 + tests/testthat/test-pretty_num.R | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/R/pretty.R b/R/pretty.R index a9704d2..0464d51 100644 --- a/R/pretty.R +++ b/R/pretty.R @@ -202,6 +202,7 @@ pretty_time_taken <- function(start_time, end_time) { #' pretty_num(567812343223, gbp = TRUE, prefix = "+/-") #' pretty_num(11^9, gbp = TRUE, dp = 3) #' pretty_num(-11^8, gbp = TRUE, dp = -1) +#' pretty_num(43.3, dp = 1, nsmall =2) #' pretty_num("56.089", suffix = "%") #' pretty_num("x") #' pretty_num("x", ignore_na = TRUE) diff --git a/tests/testthat/test-pretty_num.R b/tests/testthat/test-pretty_num.R index 95a9e61..f304707 100644 --- a/tests/testthat/test-pretty_num.R +++ b/tests/testthat/test-pretty_num.R @@ -6,12 +6,14 @@ test_that("prettifies", { expect_equal(pretty_num(1, prefix = "+/-"), "+1.00") expect_equal(pretty_num(12.289009, suffix = "%"), "12.29%") expect_equal(pretty_num(1000), "1,000.00") - expect_equal(pretty_num(11^8, gbp = TRUE, dp = -1), "£210.0 million") + expect_equal(pretty_num(11^8, gbp = TRUE, dp = -1), "£210 million") expect_equal(pretty_num(11^9, gbp = TRUE, dp = 3), "£2.358 billion") - expect_equal(pretty_num(-11^8, gbp = TRUE, dp = -1), "-£210.0 million") + expect_equal(pretty_num(-11^8, gbp = TRUE, dp = -1), "-£210 million") expect_equal(pretty_num(-123421421), "-123.42 million") + expect_equal(pretty_num(63.71, dp=1,nsmall=2), "63.70") + expect_equal(pretty_num(894.1, dp=2,nsmall=3), "894.100") expect_equal( - pretty_num(11^8, prefix = "+/-", gbp = TRUE, dp = -1.00), "+£210.0 million" + pretty_num(11^8, prefix = "+/-", gbp = TRUE, dp = -1.00), "+£210 million" ) }) @@ -27,4 +29,9 @@ test_that("tests multiple values", { pretty_num(c(1:4)), c("1.00", "2.00", "3.00", "4.00") ) + + expect_equal( + pretty_num(c(1:4), nsmall=1), + c("1.0", "2.0", "3.0", "4.0") + ) }) From a5e72f6e4fbbfdf69b75453cabe4a89ea22a03cc Mon Sep 17 00:00:00 2001 From: ZAYED Date: Mon, 7 Oct 2024 17:01:08 +0100 Subject: [PATCH 9/9] fixing formtting issues for lint testing --- R/pretty.R | 2 +- tests/testthat/test-pretty_num.R | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/R/pretty.R b/R/pretty.R index 0464d51..c481727 100644 --- a/R/pretty.R +++ b/R/pretty.R @@ -202,7 +202,7 @@ pretty_time_taken <- function(start_time, end_time) { #' pretty_num(567812343223, gbp = TRUE, prefix = "+/-") #' pretty_num(11^9, gbp = TRUE, dp = 3) #' pretty_num(-11^8, gbp = TRUE, dp = -1) -#' pretty_num(43.3, dp = 1, nsmall =2) +#' pretty_num(43.3, dp = 1, nsmall = 2) #' pretty_num("56.089", suffix = "%") #' pretty_num("x") #' pretty_num("x", ignore_na = TRUE) diff --git a/tests/testthat/test-pretty_num.R b/tests/testthat/test-pretty_num.R index f304707..09892e5 100644 --- a/tests/testthat/test-pretty_num.R +++ b/tests/testthat/test-pretty_num.R @@ -10,8 +10,8 @@ test_that("prettifies", { expect_equal(pretty_num(11^9, gbp = TRUE, dp = 3), "£2.358 billion") expect_equal(pretty_num(-11^8, gbp = TRUE, dp = -1), "-£210 million") expect_equal(pretty_num(-123421421), "-123.42 million") - expect_equal(pretty_num(63.71, dp=1,nsmall=2), "63.70") - expect_equal(pretty_num(894.1, dp=2,nsmall=3), "894.100") + expect_equal(pretty_num(63.71, dp = 1, nsmall = 2), "63.70") + expect_equal(pretty_num(894.1, dp = 2, nsmall = 3), "894.100") expect_equal( pretty_num(11^8, prefix = "+/-", gbp = TRUE, dp = -1.00), "+£210 million" ) @@ -31,7 +31,7 @@ test_that("tests multiple values", { ) expect_equal( - pretty_num(c(1:4), nsmall=1), + pretty_num(c(1:4), nsmall = 1), c("1.0", "2.0", "3.0", "4.0") ) })