diff --git a/R/utils_formatters.R b/R/utils_formatters.R index 71685f267..cc0da0973 100644 --- a/R/utils_formatters.R +++ b/R/utils_formatters.R @@ -450,7 +450,7 @@ context_minus_mark <- function(context) { context_percent_mark <- function(context) { switch(context, - html = "%", + html = "%", latex = "\\%", "%") } diff --git a/tests/testthat/test-cols_merge.R b/tests/testthat/test-cols_merge.R index 2da95472f..db2bd2de3 100644 --- a/tests/testthat/test-cols_merge.R +++ b/tests/testthat/test-cols_merge.R @@ -1,5 +1,3 @@ -context("Ensuring that the `cols_merge*()` functions work as expected") - # Create a shortened version of `mtcars` mtcars_short <- mtcars[1:5, ] @@ -480,17 +478,17 @@ test_that("the `cols_merge_n_pct()` function works correctly", { expect_equal( (tbl_html %>% render_formats_test("html"))[["a"]], c( - "1 (7.1%)", "5 (35.7%)", "0", "2 (14.3%)", - "NA", "6 (42.9%)", "5", "NA", "0", "NA" + "1 (7.1%)", "5 (35.7%)", "0", "2 (14.3%)", + "NA", "6 (42.9%)", "5", "NA", "0", "NA" ) ) expect_equal( (tbl_html %>% render_formats_test("html"))[["b"]], c( - "7.1%", "35.7%", "0.0%", "14.3%", - "NA", "42.9%", "NA", "100,000.0%", "NA", - "0.0%" + "7.1%", "35.7%", "0.0%", "14.3%", + "NA", "42.9%", "NA", "100,000.0%", "NA", + "0.0%" ) ) }) diff --git a/tests/testthat/test-conditional_fmt.R b/tests/testthat/test-conditional_fmt.R index 5d37a7122..49202123f 100644 --- a/tests/testthat/test-conditional_fmt.R +++ b/tests/testthat/test-conditional_fmt.R @@ -88,8 +88,8 @@ test_that("the `fmt_percent()` function works with conditional `rows`", { decimals = 2, rows = num_1 < 1000) %>% render_formats_test(context = "html"))[["num_1"]], - c("1836.23", "2763.39", "93,729.00%", "64,300.00%", - "21,223.20%", "0.00%", "−2,324.00%") + c("1836.23", "2763.39", "93,729.00%", "64,300.00%", + "21,223.20%", "0.00%", "−2,324.00%") ) expect_equal( @@ -99,7 +99,7 @@ test_that("the `fmt_percent()` function works with conditional `rows`", { decimals = 2, rows = char_2 %in% c("june", "july") & grepl("sa.*", char_1)) %>% render_formats_test(context = "html"))[["num_2"]], - c("3,400.00%", "74", "23", "NA", "35", "NA", "NA") + c("3,400.00%", "74", "23", "NA", "35", "NA", "NA") ) }) diff --git a/tests/testthat/test-fmt_number.R b/tests/testthat/test-fmt_number.R index 8df074abe..245f47eec 100644 --- a/tests/testthat/test-fmt_number.R +++ b/tests/testthat/test-fmt_number.R @@ -667,9 +667,9 @@ test_that("the `drop_trailing_dec_mark` option works in select `fmt_*()` functio fmt_percent(columns = num, drop_trailing_dec_mark = TRUE) %>% render_formats_test(context = "html"))[["num"]], c( - "0.10%", "1.00%", "10.00%", "0.00%", - "100.00%", "110.00%", "112.00%", "5,000,000.00%", - "−150.00%", "−500.00%", "−50,010.00%" + "0.10%", "1.00%", "10.00%", "0.00%", + "100.00%", "110.00%", "112.00%", "5,000,000.00%", + "−150.00%", "−500.00%", "−50,010.00%" ) ) @@ -679,9 +679,9 @@ test_that("the `drop_trailing_dec_mark` option works in select `fmt_*()` functio fmt_percent(columns = num, decimals = 0) %>% render_formats_test(context = "html"))[["num"]], c( - "0%", "1%", "10%", "0%", "100%", - "110%", "112%", "5,000,000%", "−150%", - "−500%", "−50,010%" + "0%", "1%", "10%", "0%", "100%", + "110%", "112%", "5,000,000%", "−150%", + "−500%", "−50,010%" ) ) @@ -692,9 +692,9 @@ test_that("the `drop_trailing_dec_mark` option works in select `fmt_*()` functio fmt_percent(columns = num, decimals = 0, drop_trailing_dec_mark = FALSE) %>% render_formats_test(context = "html"))[["num"]], c( - "0.%", "1.%", "10.%", "0.%", "100.%", - "110.%", "112.%", "5,000,000.%", "−150.%", - "−500.%", "−50,010.%" + "0.%", "1.%", "10.%", "0.%", "100.%", + "110.%", "112.%", "5,000,000.%", "−150.%", + "−500.%", "−50,010.%" ) ) diff --git a/tests/testthat/test-fmt_percent.R b/tests/testthat/test-fmt_percent.R index 082ec5af0..048c6d99e 100644 --- a/tests/testthat/test-fmt_percent.R +++ b/tests/testthat/test-fmt_percent.R @@ -35,9 +35,9 @@ test_that("the `fmt_percent()` function works correctly in the HTML context", { fmt_percent(columns = num_1, decimals = 2) %>% render_formats_test("html"))[["num_1"]], c( - "183,623.00%", "276,339.00%", "93,729.00%", - "64,300.00%", "21,223.20%", "0.00%", - "−2,324.00%" + "183,623.00%", "276,339.00%", "93,729.00%", + "64,300.00%", "21,223.20%", "0.00%", + "−2,324.00%" ) ) @@ -47,9 +47,9 @@ test_that("the `fmt_percent()` function works correctly in the HTML context", { fmt_percent(columns = num_1, decimals = 5) %>% render_formats_test("html"))[["num_1"]], c( - "183,623.00000%", "276,339.00000%", "93,729.00000%", - "64,300.00000%", "21,223.20000%", "0.00000%", - "−2,324.00000%" + "183,623.00000%", "276,339.00000%", "93,729.00000%", + "64,300.00000%", "21,223.20000%", "0.00000%", + "−2,324.00000%" ) ) @@ -61,8 +61,8 @@ test_that("the `fmt_percent()` function works correctly in the HTML context", { drop_trailing_zeros = TRUE) %>% render_formats_test("html"))[["num_1"]], c( - "183,623%", "276,339%", "93,729%", "64,300%", - "21,223.2%", "0%", "−2,324%" + "183,623%", "276,339%", "93,729%", "64,300%", + "21,223.2%", "0%", "−2,324%" ) ) @@ -73,9 +73,9 @@ test_that("the `fmt_percent()` function works correctly in the HTML context", { fmt_percent(columns = num_1, decimals = 2, use_seps = FALSE) %>% render_formats_test("html"))[["num_1"]], c( - "183623.00%", "276339.00%", "93729.00%", - "64300.00%", "21223.20%", "0.00%", - "−2324.00%" + "183623.00%", "276339.00%", "93729.00%", + "64300.00%", "21223.20%", "0.00%", + "−2324.00%" ) ) @@ -86,9 +86,9 @@ test_that("the `fmt_percent()` function works correctly in the HTML context", { fmt_percent(columns = num_1, decimals = 2, sep_mark = " ") %>% render_formats_test("html"))[["num_1"]], c( - "183 623.00%", "276 339.00%", "93 729.00%", - "64 300.00%", "21 223.20%", "0.00%", - "−2 324.00%" + "183 623.00%", "276 339.00%", "93 729.00%", + "64 300.00%", "21 223.20%", "0.00%", + "−2 324.00%" ) ) @@ -101,9 +101,9 @@ test_that("the `fmt_percent()` function works correctly in the HTML context", { sep_mark = ".", dec_mark = ",") %>% render_formats_test("html"))[["num_1"]], c( - "183.623,00%", "276.339,00%", "93.729,00%", - "64.300,00%", "21.223,20%", "0,00%", - "−2.324,00%" + "183.623,00%", "276.339,00%", "93.729,00%", + "64.300,00%", "21.223,20%", "0,00%", + "−2.324,00%" ) ) @@ -114,10 +114,10 @@ test_that("the `fmt_percent()` function works correctly in the HTML context", { fmt_percent(columns = num_1, decimals = 2, pattern = "a {x}:n") %>% render_formats_test("html"))[["num_1"]], c( - "a 183,623.00%:n", "a 276,339.00%:n", - "a 93,729.00%:n", "a 64,300.00%:n", - "a 21,223.20%:n", "a 0.00%:n", - "a −2,324.00%:n" + "a 183,623.00%:n", "a 276,339.00%:n", + "a 93,729.00%:n", "a 64,300.00%:n", + "a 21,223.20%:n", "a 0.00%:n", + "a −2,324.00%:n" ) ) @@ -129,9 +129,9 @@ test_that("the `fmt_percent()` function works correctly in the HTML context", { placement = "right", incl_space = TRUE) %>% render_formats_test("html"))[["num_1"]], c( - "183,623 %", "276,339 %", "93,729 %", - "64,300 %", "21,223 %", "0 %", - "−2,324 %" + "183,623 %", "276,339 %", "93,729 %", + "64,300 %", "21,223 %", "0 %", + "−2,324 %" ) ) @@ -143,9 +143,9 @@ test_that("the `fmt_percent()` function works correctly in the HTML context", { placement = "left", incl_space = TRUE) %>% render_formats_test("html"))[["num_1"]], c( - "% 183,623", "% 276,339", "% 93,729", - "% 64,300", "% 21,223", "% 0", - "−% 2,324" + "% 183,623", "% 276,339", "% 93,729", + "% 64,300", "% 21,223", "% 0", + "−% 2,324" ) ) @@ -155,8 +155,8 @@ test_that("the `fmt_percent()` function works correctly in the HTML context", { fmt_percent(columns = num_1, accounting = TRUE) %>% render_formats_test("html"))[["num_1"]], c( - "183,623.00%", "276,339.00%", "93,729.00%", - "64,300.00%", "21,223.20%", "0.00%", "(2,324.00%)" + "183,623.00%", "276,339.00%", "93,729.00%", + "64,300.00%", "21,223.20%", "0.00%", "(2,324.00%)" ) ) @@ -166,9 +166,9 @@ test_that("the `fmt_percent()` function works correctly in the HTML context", { fmt_percent(columns = num_1, decimals = 3, accounting = TRUE) %>% render_formats_test("html"))[["num_1"]], c( - "183,623.000%", "276,339.000%", "93,729.000%", - "64,300.000%", "21,223.200%", "0.000%", - "(2,324.000%)" + "183,623.000%", "276,339.000%", "93,729.000%", + "64,300.000%", "21,223.200%", "0.000%", + "(2,324.000%)" ) ) @@ -181,9 +181,9 @@ test_that("the `fmt_percent()` function works correctly in the HTML context", { accounting = TRUE, pattern = "a{x}b") %>% render_formats_test("html"))[["num_1"]], c( - "a183,623.000%b", "a276,339.000%b", "a93,729.000%b", - "a64,300.000%b", "a21,223.200%b", "a0.000%b", - "a(2,324.000%)b" + "a183,623.000%b", "a276,339.000%b", "a93,729.000%b", + "a64,300.000%b", "a21,223.200%b", "a0.000%b", + "a(2,324.000%)b" ) ) @@ -196,8 +196,8 @@ test_that("the `fmt_percent()` function works correctly in the HTML context", { accounting = TRUE, drop_trailing_zeros = TRUE) %>% render_formats_test("html"))[["num_1"]], c( - "183,623%", "276,339%", "93,729%", "64,300%", - "21,223.2%", "0%", "(2,324%)" + "183,623%", "276,339%", "93,729%", "64,300%", + "21,223.2%", "0%", "(2,324%)" ) ) @@ -210,8 +210,8 @@ test_that("the `fmt_percent()` function works correctly in the HTML context", { ) %>% render_formats_test("html"))[["num_1"]], c( - "+1,836.23%", "+2,763.39%", "+937.29%", - "+643%", "+212.23%", "0%", "−23.24%" + "+1,836.23%", "+2,763.39%", "+937.29%", + "+643%", "+212.23%", "0%", "−23.24%" ) ) @@ -242,9 +242,9 @@ test_that("the `fmt_percent()` function works correctly in the HTML context", { ) %>% render_formats_test("html"))[["num_1"]], c( - "*+183,623%*", "*+276,339%*", "*+93,729%*", - "*+64,300%*", "*+21,223.2%*", "*0%*", - "*−2,324%*" + "*+183,623%*", "*+276,339%*", "*+93,729%*", + "*+64,300%*", "*+21,223.2%*", "*0%*", + "*−2,324%*" ) ) @@ -255,9 +255,9 @@ test_that("the `fmt_percent()` function works correctly in the HTML context", { fmt_percent(columns = num_1, decimals = 2, locale = "en_US") %>% render_formats_test("html"))[["num_1"]], c( - "183,623.00%", "276,339.00%", "93,729.00%", - "64,300.00%", "21,223.20%", "0.00%", - "−2,324.00%" + "183,623.00%", "276,339.00%", "93,729.00%", + "64,300.00%", "21,223.20%", "0.00%", + "−2,324.00%" ) ) @@ -268,9 +268,9 @@ test_that("the `fmt_percent()` function works correctly in the HTML context", { fmt_percent(columns = num_1, decimals = 2, locale = "da_DK") %>% render_formats_test("html"))[["num_1"]], c( - "183.623,00%", "276.339,00%", "93.729,00%", - "64.300,00%", "21.223,20%", "0,00%", - "−2.324,00%" + "183.623,00%", "276.339,00%", "93.729,00%", + "64.300,00%", "21.223,20%", "0,00%", + "−2.324,00%" ) ) @@ -281,9 +281,9 @@ test_that("the `fmt_percent()` function works correctly in the HTML context", { fmt_percent(columns = num_1, decimals = 2, locale = "de_AT") %>% render_formats_test("html"))[["num_1"]], c( - "183 623,00%", "276 339,00%", "93 729,00%", - "64 300,00%", "21 223,20%", "0,00%", - "−2 324,00%" + "183 623,00%", "276 339,00%", "93 729,00%", + "64 300,00%", "21 223,20%", "0,00%", + "−2 324,00%" ) ) @@ -294,9 +294,9 @@ test_that("the `fmt_percent()` function works correctly in the HTML context", { fmt_percent(columns = num_1, decimals = 2, locale = "et_EE") %>% render_formats_test("html"))[["num_1"]], c( - "183 623,00%", "276 339,00%", "93 729,00%", - "64 300,00%", "21 223,20%", "0,00%", - "−2 324,00%" + "183 623,00%", "276 339,00%", "93 729,00%", + "64 300,00%", "21 223,20%", "0,00%", + "−2 324,00%" ) ) @@ -307,9 +307,9 @@ test_that("the `fmt_percent()` function works correctly in the HTML context", { fmt_percent(columns = num_1, decimals = 2, locale = "gl_ES") %>% render_formats_test("html"))[["num_1"]], c( - "183.623,00%", "276.339,00%", "93.729,00%", - "64.300,00%", "21.223,20%", "0,00%", - "−2.324,00%" + "183.623,00%", "276.339,00%", "93.729,00%", + "64.300,00%", "21.223,20%", "0,00%", + "−2.324,00%" ) ) @@ -320,8 +320,8 @@ test_that("the `fmt_percent()` function works correctly in the HTML context", { fmt_percent(columns = num_2, decimals = 2, scale_values = FALSE) %>% render_formats_test("html"))[["num_2"]], c( - "34.00%", "74.00%", "23.00%", "93.00%", - "35.00%", "76.00%", "57.00%" + "34.00%", "74.00%", "23.00%", "93.00%", + "35.00%", "76.00%", "57.00%" ) ) })