Skip to contents

Given a named numeric vector of foods and their gram weights, looks up each food across all IFCT tables, scales every nutrient by grams / 100 (all IFCT values are per 100 g edible portion), and returns per-table totals.

Usage

compose_meal(foods, match = c("fixed", "regex"))

Arguments

foods

Named numeric vector: names are food search strings (matched exactly or by substring against food names / food codes), values are the gram amounts to include. Example: c("Rice" = 100, "Wheat flour" = 50, "Bengal gram" = 30).

match

One of "fixed" (default) or "regex".

Value

A named list of tibbles, one per IFCT table. Each tibble has a leading food column showing which ingredient contributed each row, plus grams (the portion size), followed by all nutrient columns scaled to that portion. The last row of every tibble is a "TOTAL" summary row that sums each nutrient column across all ingredients. Units are preserved from the column names (g, mg, μg, KJ).

Examples

meal <- compose_meal(c("Rice" = 150, "Dal" = 100, "Spinach" = 50))
#>  Meal composed: 3 ingredients across 12 tables.
meal$proximate
#> # A tibble: 4 × 11
#>   food        grams `Water(g)` `Protein_PROTCNT(g)` `Ash(g)` `TotalFat_FATCE(g)`
#>   <chr>       <dbl>      <dbl>                <dbl>    <dbl>               <dbl>
#> 1 "(Oryza sa…   150      15.5                 11.2      1.27                1.71
#> 2 "Bengal gr…   100       9.18                21.6      2.1                 5.31
#> 3 "Spinach (…    50      45.2                  1.07     1.24                0.32
#> 4 "TOTAL"       300      69.9                 33.8      4.61                7.34
#> # ℹ 5 more variables: `TotalDietaryFibre_FIBTG(g)` <dbl>,
#> #   `InsolubleFibre_FIBINS(g)` <dbl>, `SolubleFibre_FINSOL(g)` <dbl>,
#> #   `AvailableCarbohydrate_CHOAVLDF(g)` <dbl>, `Energy_ENERC(KJ)` <dbl>
meal$minerals
#> # A tibble: 4 × 22
#>   food                grams `Aluminium_Al(mg)` `Arsenic_As(μg)` `Cadmium_Cd(mg)`
#>   <chr>               <dbl>              <dbl>            <dbl>            <dbl>
#> 1 Rice flakes (Oryza…   150              3.66                NA            0.003
#> 2 Bengal gram, dal (…   100              0.65                NA           NA    
#> 3 Spinach (Spinacia …    50              0.755               NA           NA    
#> 4 TOTAL                 300              5.07                 0            0.003
#> # ℹ 17 more variables: `Calcium_Ca(mg)` <dbl>, `Chromium_Cr(mg)` <dbl>,
#> #   `Cobalt_Co(mg)` <dbl>, `Copper_Cu(mg)` <dbl>, `Iron_Fe(mg)` <dbl>,
#> #   `Lead_Pb(mg)` <dbl>, `Lithium_Li(mg)` <dbl>, `Magnesium_Mg(mg)` <dbl>,
#> #   `Manganese_Mn(μg)` <dbl>, `Mercury_Hg(mg)` <dbl>,
#> #   `Molybdenum_Mo(mg)` <dbl>, `Nickel_Ni(mg)` <dbl>, `Phosphorus_P(mg)` <dbl>,
#> #   `Potassium_K(mg)` <dbl>, `Selenium_Se(μg)` <dbl>, `Sodium_Na(mg)` <dbl>,
#> #   `Zinc_Zn(mg)` <dbl>