Skip to contents

Extracts unique food items from dietary recall data where units are not measured in grams ("g from scale" or "g from photobook"). Combines results from food_details and food_ingredients_group and links them with household location information from maintable.

Usage

get_non_gram_foods(
  maintable,
  food_details,
  food_ingredients,
  location_col,
  key = "survey_id",
  export_path = NULL
)

Arguments

maintable

A data frame with survey-level information (must include key and the specified location_col).

food_details

A data frame with food details (must include key, desc_of_food, and unit_qty_food_consumed).

food_ingredients

A data frame with food ingredients (must include key, food_ingredients_used, and food_ingredient_unit).

location_col

Character string. Name of the location column in maintable (e.g., subcounty, district). Must be provided explicitly.

key

Character string. The column name that uniquely links maintable, food_details, and food_ingredients. Typically survey_id.

export_path

Optional. File path to export results as an Excel file. If supplied, the Excel file will be created with all required columns and empty amount and gram fields for later user input.

Value

A tibble with columns:

location_col

Location identifier column, as specified in maintable

food_item

Food item consumed or ingredient used

unit

Original unit recorded (not grams)

amount

Empty column for later input

gram

Empty column for later input

Details

Optionally, the results can be exported to Excel. The exported file contains all relevant columns, with two extra empty columns (amount, gram) for user input. Users are expected to fill in only these two columns and should avoid modifying the location column, food_item, or unit.

If all food items in the dataset are recorded in grams ("g from scale" or "g from photobook"), the function will return an empty tibble with the correct columns, print a message to the user, and skip Excel export (even if export_path is provided).

Examples

data("dietrecall_example")
get_non_gram_foods(
  maintable = dietrecall_example$maintable,
  food_details = dietrecall_example$food_details,
  food_ingredients = dietrecall_example$food_ingredients_group,
  location_col = "subcounty",
  key = "survey_id"
)
#> # A tibble: 83 × 5
#>    subcounty food_item                                        unit  amount  gram
#>    <chr>     <chr>                                            <chr>  <dbl> <dbl>
#>  1 MAKADARA  Orange (chungwa), pulp, raw                      Pric…     NA    NA
#>  2 MAKADARA  Githeri (Stewed Maize & Beans)                   mls       NA    NA
#>  3 MAKADARA  Beans, kidney, dry, water-soaked, boiled in dif… mls       NA    NA
#>  4 MAKADARA  Black Bean Stew                                  mls       NA    NA
#>  5 MAKADARA  White Chapati                                    Pric…     NA    NA
#>  6 MAKADARA  Chai ya Maziwa (Mixed Tea)                       mls       NA    NA
#>  7 MAKADARA  Amaranth (terere), leaves, picked, stewed        mls       NA    NA
#>  8 MAKADARA  Green Grams (ndengu), dry, unsoaked, boiled      Pric…     NA    NA
#>  9 MAKADARA  Potato Chips (French Fries)                      Pric…     NA    NA
#> 10 MAKADARA  Basic Mandazi                                    Pric…     NA    NA
#> # ℹ 73 more rows