Skip to contents

Produces a unified dataset of foods and ingredients reported in a dietary recall, keeping only the survey identifier (key) and the harmonized food item name.

Usage

harmonize_food_and_ingredients(
  food_details,
  food_ingredients,
  key = "survey_id",
  include_rowid = FALSE
)

Arguments

food_details

A data frame with food-level information (must include the column specified in key and desc_of_food).

food_ingredients

A data frame with ingredient-level information (must include the column specified in key and food_ingredients_used).

key

Character string. The column name that uniquely links records across food_details and food_ingredients. Defaults to "survey_id".

include_rowid

Logical, default = FALSE. If TRUE, the output includes food_details_rowid, allowing harmonized foods and ingredients to be traced back to the original food-level record. The default keeps the original two-column output for backward compatibility.

Value

A tibble containing:

Survey identifier

The column specified by the key argument.

food_details_rowid

Food-level row identifier. Returned only when include_rowid = TRUE.

food_item

Name of food or ingredient.

Details

  • Foods with NA in desc_of_food are excluded.

  • No deduplication is forced: if the same item appears in both foods and ingredients, both records are returned.

  • This function is primarily used for harmonizing raw item names before linking to external food composition or coding systems.

Examples

data("dietrecall_example")
result <- harmonize_food_and_ingredients(
  food_details = dietrecall_example$food_details,
  food_ingredients = dietrecall_example$food_ingredients_group,
  key = "survey_id"
)
head(result)
#> # A tibble: 6 × 2
#>   survey_id         food_item                                                  
#>   <chr>             <chr>                                                      
#> 1 0111251492-161123 Orange (chungwa), pulp, raw                                
#> 2 0111251492-161123 Bread, White                                               
#> 3 0111251492-241023 Githeri (Stewed Maize & Beans)                             
#> 4 0111251492-241023 Bread, White                                               
#> 5 0111323284-291023 Beans, kidney, dry, water-soaked, boiled in different water
#> 6 0111323284-291023 White Chapati