1
0
mirror of https://github.com/msberends/AMR.git synced 2025-07-08 07:51:57 +02:00

(v0.7.1.9023) wrong percentage in as.mo()

This commit is contained in:
2019-08-04 17:41:12 +02:00
parent 643c5ed807
commit 85b62aaf8f
11 changed files with 35 additions and 33 deletions

View File

@ -71,18 +71,20 @@ size_humanreadable <- function(bytes, decimals = 1) {
out
}
percent_scales <- scales::percent
percent_clean <- clean:::percent
# No export, no Rd
# based on scales::percent
percent <- function(x, round = 1, force_zero = FALSE, decimal.mark = getOption("OutDec"), ...) {
x <- percent_scales(x = as.double(x),
accuracy = 1 / 10 ^ round,
decimal.mark = decimal.mark,
...)
if (force_zero == FALSE) {
x <- gsub("([.]%|%%)", "%", paste0(gsub("0+%$", "", x), "%"))
percent <- function(x, round = 1, force_zero = FALSE, decimal.mark = getOption("OutDec"), big.mark = ",", ...) {
if (decimal.mark == big.mark) {
if (decimal.mark == ",") {
big.mark <- "."
} else if (decimal.mark == ".") {
big.mark <- ","
} else {
big.mark <- " "
}
}
x
x <- percent_clean(x = x, round = round, force_zero = force_zero,
decimal.mark = decimal.mark, big.mark = big.mark, ...)
}
#' @importFrom crayon blue bold red

4
R/mo.R
View File

@ -1238,10 +1238,10 @@ exec_as.mo <- function(x,
if (n_distinct(failures) > 1) {
plural <- c("values", "them", "were")
}
total_failures <- length(x_input[x_input %in% failures & !x_input %in% c(NA, NULL, NaN)])
total_failures <- length(x_input[as.character(x_input) %in% as.character(failures) & !x_input %in% c(NA, NULL, NaN)])
total_n <- length(x_input[!x_input %in% c(NA, NULL, NaN)])
msg <- paste0(nr2char(n_distinct(failures)), " unique ", plural[1],
" (^= ", percent(total_failures / total_n, round = 1, force_zero = TRUE),
" (covering ", percent(total_failures / total_n, round = 1, force_zero = TRUE),
") could not be coerced and ", plural[3], " considered 'unknown'")
if (n_distinct(failures) <= 10) {
msg <- paste0(msg, ": ", paste('"', unique(failures), '"', sep = "", collapse = ', '))