From c6ef41ca4ebe35ddac3b7c46fff638ab101d57eb Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 6 Nov 2024 23:28:41 +0100 Subject: [PATCH] fix --- R/format_bf.R | 14 +++++++++++--- R/format_p.R | 10 ++++++++-- tests/testthat/test-format.R | 4 ++++ 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/R/format_bf.R b/R/format_bf.R index ac3d63e46..81c850ab2 100644 --- a/R/format_bf.R +++ b/R/format_bf.R @@ -87,14 +87,22 @@ format_bf <- function(bf, ) ) - ## Add stars - bf_text <- ifelse(bf_orig < (1 / 30), paste0(bf_text, paste(rep_len(inferiority_star, 3), collapse = "")), # nolint + ## Add inferiority stars + if (!is.null(inferiority_star)) { + bf_text <- ifelse(bf_orig < (1 / 30), paste0(bf_text, paste(rep_len(inferiority_star, 3), collapse = "")), # nolint ifelse(bf_orig < 0.1, paste0(bf_text, paste(rep_len(inferiority_star, 2), collapse = "")), # nolint ifelse(bf_orig < (1 / 3), paste0(bf_text, inferiority_star), bf_text) # nolint ) ) + } - out <- .add_prefix_and_remove_stars(p_text = bf_text, stars, stars_only, name, inferiority_star) + out <- .add_prefix_and_remove_stars( + p_text = bf_text, + stars = stars, + stars_only = stars_only, + name = name, + inferiority_star = inferiority_star + ) if (is.na(na_reference)) out[bad_bf] <- "" out } diff --git a/R/format_p.R b/R/format_p.R index 432858a0e..0965adf9e 100644 --- a/R/format_p.R +++ b/R/format_p.R @@ -123,10 +123,16 @@ format_p <- function(p, } if (stars_only) { - p_text <- gsub(paste0("[^(\\*|", inferiority_star, ")]"), "", p_text) + if (is.null(inferiority_star)) { + p_text <- gsub(paste0("[^(\\*)]"), "", p_text) + } else { + p_text <- gsub(paste0("[^(\\*|", inferiority_star, ")]"), "", p_text) + } } else if (!stars) { p_text <- gsub("*", "", p_text, fixed = TRUE) - p_text <- gsub(inferiority_star, "", p_text, fixed = TRUE) + if (!is.null(inferiority_star)) { + p_text <- gsub(inferiority_star, "", p_text, fixed = TRUE) + } } # replace missing with related string diff --git a/tests/testthat/test-format.R b/tests/testthat/test-format.R index 87d526384..ab6c6b717 100644 --- a/tests/testthat/test-format.R +++ b/tests/testthat/test-format.R @@ -114,6 +114,10 @@ test_that("format others", { format_bf(c(0.000045, 0.233, NA, 1557, 3.54), stars = TRUE), c("BF < 0.001°°°", "BF = 0.233°", "", "BF > 1000***", "BF = 3.54*") ) + expect_identical( + format_bf(c(0.000045, 0.233, NA, 1557, 3.54), stars = TRUE, inferiority_star = NULL), + c("BF < 0.001", "BF = 0.233", "", "BF > 1000***", "BF = 3.54*") + ) expect_identical( format_bf(c(0.000045, 0.233, NA, 1557, 3.54), stars = TRUE, stars_only = TRUE), c("°°°", "°", "", "***", "*")