R/health.R

#' Calculate BMI
#'
#' With this function you can calculate your BMI.
#'
#' @param weight your weight in kg or lb
#' @param height height in meters or inches
#' @param system one of `metric` or `imperial`
#'
#' @return BMI
#'
#' @export
#'
#' @examples
#' bmiCalc(75, 1.70)
bmiCalc <- function(weight, height, system = "metric") {
  if (!system %in% c("metric", "imperial")) {
    stop("`system` should only be `metric` or `imperial`.")
  }
  if (system == "metric") {
    bmi <- weight / (height ^ 2)
  }
  if (system == "imperial") {
    bmi <- (weight / (height ^ 2)) * 703
  }
  return(bmi)
}

#' Calculate BMR
#'
#' With this function you can calculate your basale metabolic rate..
#'
#' @param weight your weight in kg
#' @param height height in centimeters
#' @param age age in years
#' @param sex one of `male` or `female`
#'
#' @return BMR
#'
#' @export
#'
#' @examples
#' bmrCalc(70, 180, 30, "male")
bmrCalc <- function(weight, height, age, sex = "male") {
  if (!sex %in% c("male", "female")) {
    stop("`sex` should only be `male` or `female`.")
  }
  if (sex == "male") {
    bmr <-  (9.99 * weight) + (6.25 * height) + (4.92 * age) + 5
  }
  if (sex == "female") {
    bmr <- (9.99 * weight) + (6.25 * height) + (4.92 * age) - 161
  }
  return(bmr)
}



#' Calculate TDEE
#'
#' With this function you can calculate your total daily energe expenditure
#'
#' @param weight your weight in kg
#' @param height height in centimeters
#' @param age age in years
#' @param sex one of `male` or `female`
#' @param objective integer between 0.8 - 1.3
#' @param effort integer between 1.2 - 1.8
#'
#' @return BMR
#'
#' @export
#'
#' @examples
#' tdeeCalc(70, 180, 30, "male", 1, 1.5)
tdeeCalc <-
  function(weight,
           height,
           age,
           sex = "male",
           objective,
           effort) {
    if (objective < 0.8 | objective > 1.3) {
      stop("Your `ojbective` should be between 0.8 and 1.3")
    }
    if (effort < 1.2 | effort > 1.8) {
      stop("Your `ojbective` should be between 0.8 and 1.3")
    }
    bmr <- bmrCalc(weight, height, age, sex)
    tdee <- bmr * objective * effort
    return(tdee)
  }
MarijnJABoer/HeavySetR documentation built on May 22, 2019, 5:31 p.m.