R/bmi.R

Defines functions bmi

Documented in bmi

# Generated by fusen: do not edit by hand

#' bmi Body Mass Index of an individual
#'
#' @param mass in kg
#' @param height in m
#' @return bmi as mass/(height * height)
#' @importFrom assertthat assert_that
#' @importFrom dplyr mutate
#' @export
#'
#' @examples
#' bmi(mass = 80, height = 1.80)
#' bmi(mass = NA, height = 1.80)
#' bmi(mass = 80, height = NA)
#' bmi(mass = NA, height = NA)
bmi <- function(mass, height) {
  if(!(is.na(mass)|(is.numeric(mass)&mass>0))) {stop("mass should be numeric and >0")}
  if(!(is.na(height)|(is.numeric(height)&height>0))) {stop("height should be numeric and >0")}
  bmi <- NA
  if (!is.na(mass)&!is.na(height)) {
    bmi <- mass/(height * height)
  }
  return(bmi)
}
choogland/christinehoogland.pkg documentation built on May 7, 2022, 12:05 a.m.