inst/examples/max_if.R

#' Calculate maximum and return NA if input is empty
#'
#' This is a helper function that returns NA if length(x) == 0 (e.g., is 
#' numeric(0)), otherwise calculates the maximum
#'
#' @param x numeric
#' @param ... additional arguments for max
#'
#' @return either NA or the maximum value
#' @noRd
#' @examples
#' \dontrun{
#' max_if(numeric(0))
#' }
#' @name safe_minima
max_if <- function(x, ...){
  ifelse(test = length(x) == 0,
         yes = NA,
         no = max(x, ...))
}

Try the brolgar package in your browser

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

brolgar documentation built on June 22, 2024, 11:24 a.m.