Calculate Eugenol Intake

This script takes in your disaggregated dietary data and FooDB-linked descriptions to calculate eugenol intake per recall (or record) and subject.

INPUTS

  • Diet_Disaggregated_mapped.csv.bz2 - Disaggregated dietary data, mapped to FooDB foods, From Step 2 of the polyphenol estimation pipeline
  • FooDB_Eugenol_Content_Final.csv - Eugenol Content for foods in FooDB, Provided File

OUTPUTS

  • Diet_DII_eugenol_by_entry.csv: Sum eugenol content for each participant recall or record

SCRIPT

Load packages

suppressMessages(library(dplyr))
suppressMessages(library(vroom))
suppressMessages(library(tidyr))
suppressMessages(library(stringr))

Load data

# Load provided file paths
source("provided_files.R")

# Load Dietary data that has been disaggregated and connected to FooDB
input_mapped = vroom::vroom('outputs/Diet_Disaggregated_mapped.csv.bz2', 
                            show_col_types = FALSE)

# Eugenol Content in FooDB
# Note: Eugenol doesn't have retention factors from Phenol Explorer
eugenol = vroom::vroom(FooDB_eugenol, show_col_types = FALSE) %>%
  dplyr::select(-c(source_type, food_name:orig_source_name))

Specify grouping variables

Column grouping depends on whether output is from a record or recall.

if ("RecallNo" %in% names(input_mapped)) {
  group_vars = c("subject", "RecallNo")
  
} else if ("RecordNo" %in% names(input_mapped)) {
  group_vars = c("subject", "RecordNo", "RecordDayNo")
  
} else {
  stop("Data must contain RecallNo or RecordNo.")
}

Merge FooDB-matched Ingredient Codes to FooDB Eugenol Content File.

  • Link between FooDB Polyphenol Content and code-matched data is food_id.
input_mapped_content = input_mapped %>%
  # Bring in the Polyphenol Content
  dplyr::left_join(eugenol, by = 'food_id') %>%
  # Remove content that is NA
  dplyr::filter(!is.na(orig_content_avg)) %>%
  # Calculate eugenol amount consumed in milligrams
  dplyr::mutate(eugenol_mg = (orig_content_avg * 0.01) * FoodAmt_Ing_g) %>%
  # Recall - Sum by Subject, Recall
  # Record - Sum by Subject, Record Number, Day in Record Number
  dplyr::group_by(across(all_of(group_vars))) %>%
  # Calculate EUGENOL summed per recal or record
  # with rename for dietaryindex function
  dplyr::mutate(EUGENOL = sum(eugenol_mg)) %>%
  dplyr::ungroup() %>%
  dplyr::select(c(subject, any_of(c("RecallNo", "RecordNo", "RecordDayNo")), EUGENOL)) %>%
  # Keep distinct entries
  dplyr::distinct(across(all_of(group_vars)), .keep_all = TRUE)

Export Eugenol Intake File for DII Calculation

vroom::vroom_write(input_mapped_content, 'outputs/Diet_DII_eugenol_by_entry.csv', delim = ",")