Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions R/util.R
Original file line number Diff line number Diff line change
Expand Up @@ -3017,7 +3017,7 @@ construct_new_labels <- function(base.labels, new.labels) {
# Example
# Input: "(0.996,2.33]", "(2.33,3.67]", "(3.67,5]"
# Output: "0.996 - 2.33", "2.33 - 3.67", "3.67 - 5"
format_cut_output <- function(x, decimal.digits=2, big.mark=",", small.mark=".", new.labels=NULL, prefix="", suffix="", right=TRUE) {
format_cut_output <- function(x, decimal.digits=2, big.mark=",", small.mark="", new.labels=NULL, prefix="", suffix="", right=TRUE) {
# Exit if the length is 0.
if (length(x) == 0 || all(is.na(x))) {
return (x)
Expand Down Expand Up @@ -3045,7 +3045,7 @@ format_cut_output <- function(x, decimal.digits=2, big.mark=",", small.mark=".",
# Input: [1] "(0.996,2.333333333]" "(2.333333333,3.666666667]" "(3.666666667,5.004]"
# Output: [1] "1.00 - 2.33" "2.33 - 3.67" "3.67 - 5.00"
#
format_cut_output_levels <- function(x, decimal.digits=2, big.mark=",", small.mark=".", prefix="", suffix="", right=TRUE) {
format_cut_output_levels <- function(x, decimal.digits=2, big.mark=",", small.mark="", prefix="", suffix="", right=TRUE) {
# Split the text by ",". It will breaks the vector like this.
# [[1]]
# [1] "(0.996" "2.333333333]"
Expand Down
6 changes: 6 additions & 0 deletions tests/testthat/test_util.R
Original file line number Diff line number Diff line change
Expand Up @@ -1746,6 +1746,12 @@ test_that("format_cut_output function", {
formatted <- format_cut_output(x)
expect_equal(formatted, factor(c("1.00 - 2.33","1.00 - 2.33","2.33 - 3.67","3.67 - 5.00","3.67 - 5.00")))

# decimal.digits is more than 6 case.
# It shouldn't show the small mark "." between 6th and 7th decimal digit
# like "0.996000.00". #27137.
formatted <- `_tam_format_cut_output`(x, decimal.digits=8)
expect_equal(formatted, factor(c("0.99600000 - 2.33333333", "0.99600000 - 2.33333333", "2.33333333 - 3.66666667", "3.66666667 - 5.00400000","3.66666667 - 5.00400000")))

# Negative test
expect_equal(c(NA,NA,NA), format_cut_output(c(NA,NA,NA), decimal.digits=2))
expect_equal(NULL, format_cut_output(c(), decimal.digits=2))
Expand Down