Skip to content

Commit

Permalink
Modify ndecimals() to recognize any decimal delimiter (comma in French)
Browse files Browse the repository at this point in the history
  • Loading branch information
cgrandin committed Oct 21, 2024
1 parent 5989da8 commit 56ac899
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ factor_bin_clean <- function(x, bins, clean = TRUE) {
out <- bins[findInterval(x, bins, rightmost.closed = TRUE)]
max_char <- max(nchar(out))
ndec <- ndecimals(out)

if (clean & ndec == 0) {
out <- sprintf(paste0("%0", max_char, "d"), out)
} # pad with zeros
Expand Down Expand Up @@ -118,7 +119,10 @@ factor_clean <- function(x) {
}

ndecimals <- function(x) {
ndec <- nchar(lapply(strsplit(as.character(x), "\\."), function(x) x[2]))
ndec <- nchar(lapply(strsplit(as.character(x),
options("OutDec")),
\(x) x[2]))

if (!all(is.na(ndec))) {
ndec <- max(ndec, na.rm = TRUE)
} else {
Expand Down

0 comments on commit 56ac899

Please sign in to comment.