Computes the actual gram intake for foods and ingredients from dietary recall
data. Handles both gram-based and non-gram units, with support for user-
provided non-gram conversion data (from get_non_gram_foods()).
Usage
compute_actual_g_intake(
maintable,
food_details,
food_ingredients,
non_gram_foods = NULL,
location_col,
key = "survey_id",
group = TRUE
)Arguments
- maintable
A data frame with survey-level information (must include the column specified in
keyand the specifiedlocation_col).- food_details
A data frame with food-level information (must include the column specified in
key, plusdesc_of_food,qty_food_consumed,unit_qty_food_consumed, andfood_item_price_prop_consumed).- food_ingredients
A data frame with ingredient-level information (must include the column specified in
key,food_details_rowid,food_ingredients_used,food_ingredient_amt, andfood_ingredient_unit).- non_gram_foods
Optional. A data frame produced from
get_non_gram_foods()and filled by the user with conversions (must includefood_item,unit,amount, andgram). IfNULL, the function will check for non-gram units and stop if found.- location_col
Character string. Name of the location column in
maintable(e.g.,"subcounty","district").- key
Character string. The column name that uniquely links
maintable,food_details, andfood_ingredients. Defaults to"survey_id".- group
Logical, default =
TRUE. IfTRUE, results are aggregated bykeyandfood_item, returning summedactual_gram_intakeonly. IfFALSE, detailed row-level data is returned, includingfood_details_rowidfor tracing foods and ingredients back to the original food-level record.
Value
A tibble:
If
group = TRUE: columnskey,food_item, andactual_gram_intake.If
group = FALSE: detailed row-level columns includingfood_details_rowid,amt_consumed,unit,prop_consumed,gram_per_unit, andactual_gram_intake.
Details
If
non_gram_foodsisNULLand non-gram units are found, the function will stop and request a conversion sheet.If provided,
non_gram_foodsmust include the same location column (specified inlocation_col), along with columnsfood_item,unit,amount, andgram.The function warns the user if any non-gram foods lack a valid
gram_per_unit.
Examples
data("dietrecall_example")
data("non_gram_foods_conversion")
# Default: grouped output, ready for FCT merge
result_grouped <- compute_actual_g_intake(
maintable = dietrecall_example$maintable,
food_details = dietrecall_example$food_details,
food_ingredients = dietrecall_example$food_ingredients_group,
non_gram_foods = non_gram_foods_conversion,
location_col = "subcounty",
key = "survey_id",
group = FALSE
)
head(result_grouped)
#> # A tibble: 6 × 8
#> survey_id food_details_rowid food_item amt_consumed unit prop_consumed
#> <chr> <dbl> <chr> <dbl> <chr> <dbl>
#> 1 0111251492-1611… 1 Orange (… 10 Pric… 1
#> 2 0111251492-1611… 6 Bread, W… 104 g fr… 1
#> 3 0111251492-2410… 3 Githeri … 142 mls 1
#> 4 0111251492-2410… 4 Bread, W… 400 g fr… 1
#> 5 0111323284-2910… 3 Beans, k… 73 g fr… 1
#> 6 0111323284-2910… 4 White Ch… 214 g fr… 1
#> # ℹ 2 more variables: gram_per_unit <dbl>, actual_gram_intake <dbl>
# Detailed output (row-level), useful for debugging
# \donttest{
result_detailed <- compute_actual_g_intake(
maintable = dietrecall_example$maintable,
food_details = dietrecall_example$food_details,
food_ingredients = dietrecall_example$food_ingredients_group,
non_gram_foods = non_gram_foods_conversion,
location_col = "subcounty",
key = "survey_id"
)
head(result_detailed)
#> # A tibble: 6 × 3
#> survey_id food_item actual_gram_intake
#> <chr> <chr> <dbl>
#> 1 0111251492-161123 Amaranth (terere), leaves, picked, raw 328.
#> 2 0111251492-161123 Bread, White 104
#> 3 0111251492-161123 Cooking Oil 467.
#> 4 0111251492-161123 Drinking chocolate (cocoa), powder 44.7
#> 5 0111251492-161123 Kale (sukuma wiki) raw 332.
#> 6 0111251492-161123 Maize meal, sifted, fortified, packaged,… 525
# }