R/macro.R

Defines functions calculate_protein_intake calculate_macros

Documented in calculate_macros calculate_protein_intake

#' @title Calculate macro's
#'
#' @description
#' \lifecycle{stable}
#'
#' Calculate carbohydrate, protein and fat balance in grams based on the
#' estimated daily total energy expenditure (TDEE). The acceptable macronutrient
#' distribution ranges (AMDR) are 45–65% of your daily calories from carbs,
#' 20–35% from fats and 10–35% from protein.
#'
#' @param tdee Total daily energy expenditure
#' @param balance Macro balance. Should sum to 1, Default: c(c = 0.5, p = 0.25,
#'   f = 0.25)
#'
#' @return list of macro's in gram
#'
#' @details Translating to grams is as followed:
#' - 1 gram of protein equals 4 calories
#' - 1 gram of carbohydrates equals 4 calories
#' - 1 gram of fat equals 9 calories
#'
#' @references
#' National Research Council (US) Committee on Diet and Health. Diet
#' and Health: Implications for Reducing Chronic Disease Risk. Washington (DC):
#' National Academies Press (US); 1989. 6, Calories: Total Macronutrient Intake,
#' Energy Expenditure, and Net Energy Stores. Available from:
#' https://www.ncbi.nlm.nih.gov/books/NBK218769/
#'
#' @examples
#' ## Standard
#' calculate_macros(tdee = 2565, balance = c(c = 0.5, p = 0.25, f = 0.25))
#'
#' ## Keto
#' calculate_macros(tdee = 2565, balance = c(c = 0.05, p = 0.25, f = 0.7))
#' @rdname calculate_macros
#' @export
#' @importFrom checkmate assert_number assert_numeric
calculate_macros <-
  function(tdee, balance = c(c = 0.5, p = 0.25, f = 0.25)) {
    checkmate::assert_number(tdee, lower = 0)
    checkmate::assert_numeric(
      balance,
      lower = 0,
      upper = 1,
      any.missing = FALSE,
      len = 3
    )
    if (sum(balance) != 1) {
      stop("Error: the sum of balance should be equal to 1. It is now ",
           sum(balance),
           ".")
    }
    carbs <- kcal_to_carbs(tdee * balance["c"])
    protein <- kcal_to_protein(tdee * balance["p"])
    fat <- kcal_to_fat(tdee * balance["f"])
    res <- round(c(carbs, protein, fat), 2)
    return(res)
  }

#' @title Calculate protein intake
#'
#' @description Calculate the protein intake for you weight across a range from
#' the Recommended Dietary Allowances (RDA) to 2 times the RDA.
#'
#' @param weight weight in kg.
#'
#' @return Dataframe of protein intake across a range
#'
#' @details
#' \url{https://pubmed.ncbi.nlm.nih.gov/22150425/}
#' Protein intake 1.3-1.8 g per kg body weight per day for athletes
#' When cutting  (caloric deficit) 1.8-2.0 for athletes.
#'
#' \url{https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4018950/}
#' You should distribute the protein intake evenly over your meals
#' RDA = 0.8 g per kg body weight per day
#'
#' \url{https://www.ncbi.nlm.nih.gov/pmc/articles/PMC5828430/}
#' 1.6 g p kg for maximizing anabolism. across 4 meals ado
#'
#' @examples
#' calculate_protein_intake(80)
#' @rdname calculate_protein_intake
#' @export
#' @importFrom checkmate assert_number
#' @importFrom stats setNames
calculate_protein_intake <- function(weight) {
  # TODO(MJABOER): touch up details of description
  checkmate::assert_number(weight, lower = 0)
  range <- seq(0.8, 1.6, 0.1)
  intake <- range * weight
  df <-
    stats::setNames(data.frame(cbind(range, intake)),
                    c("Grams of protein per kg bodyweight",
                      "Grams of protein intake"))
  return(df)
}
MarijnJABoer/befitteR documentation built on April 24, 2020, 5:43 a.m.