R/misc.R

#' Character sign of an argument
#'
#' Returns "+" for positive arguments, "-" for negative and `zero` for 0.
#'
#' @param x a numeric vector
#' @param zero character to return for 0 argument
#'
#' @examples
#' signc(-1:1)
#' signc(-1:1, zero = "|")
#'
#' @export
signc <- function(x, zero = "0") {
  if (!is.numeric(x)) stop("x should be numeric")
  str <- ifelse(x >= 0, "+", "-")
  str[x == 0] <- zero
  str
}
avidclam/amxtra documentation built on May 17, 2019, 12:01 p.m.