R/format_pd.R

Defines functions format_pd

Documented in format_pd

#' Probability of direction (pd) formatting
#'
#' @param pd Probability of direction (pd).
#' @inheritParams format_p
#'
#' @return A formatted string.
#' @examples
#' format_pd(0.12)
#' format_pd(c(0.12, 1, 0.9999, 0.98, 0.995, 0.96), name = NULL)
#' format_pd(c(0.12, 1, 0.9999, 0.98, 0.995, 0.96), stars = TRUE)
#' @export
format_pd <- function(pd, stars = FALSE, stars_only = FALSE, name = "pd") {
  text <- ifelse(pd >= 1, "= 100%***",
    ifelse(pd > 0.999, paste0("= ", format_value(pd * 100), "%***"), # nolint
      ifelse(pd > 0.99, paste0("= ", format_value(pd * 100), "%**"), # nolint
        ifelse(pd > 0.97, paste0("= ", format_value(pd * 100), "%*"), # nolint
          paste0("= ", format_value(pd * 100), "%")
        )
      )
    )
  )

  .add_prefix_and_remove_stars(text, stars, stars_only, name)
}

Try the insight package in your browser

Any scripts or data that you put into this service are public.

insight documentation built on Nov. 26, 2023, 5:08 p.m.