| Title: | Calculate the Cost and Environmental Impact of a Ideal Diet |
|---|---|
| Description: | Easily perform a Monte Carlo simulation to evaluate the cost and carbon, ecological, and water footprints of a set of ideal diets. Pre-processing tools are also available to quickly treat the data, along with basic statistical features to analyze the simulation results — including the ability to establish confidence intervals for selected parameters, such as nutrients and price/emissions. A 'standard version' of the datasets employed is included as well, allowing users easy access to customization. This package brings to R the 'Python' software initially developed by Vandevijvere, Young, Mackay, Swinburn and Gahegan (2018) <doi:10.1186/s12966-018-0648-6>. |
| Authors: | Henrique Bracarense [cre, aut] (ORCID: <https://orcid.org/0009-0001-5964-9969>), Thais Marquezine [aut] (ORCID: <https://orcid.org/0000-0002-9415-5817>), Rafael Claro [aut] (ORCID: <https://orcid.org/0000-0001-9690-575X>) |
| Maintainer: | Henrique Bracarense <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 1.0.0.0 |
| Built: | 2026-06-10 07:33:34 UTC |
| Source: | https://github.com/hbracarense/dietcost |
Checks if a numeric variable is within a continuous float range.
add_float_range(variable, min, max)add_float_range(variable, min, max)
variable |
Numeric variable. |
min |
Minimum possible value. |
max |
Maximum possible value. |
No return value,only performs a check.
Checks if a variable is within a discrete range.
add_range(variable, range, message)add_range(variable, range, message)
variable |
variable. |
range |
Allowed range. |
message |
Message to be printed in case of failure. |
No return value, only performs a check.
Adds nutrients constraint data, according to chosen diet, to foods dataframe.
addConstraintData(filepath, df, diets, max_scale, override_min = NULL)addConstraintData(filepath, df, diets, max_scale, override_min = NULL)
filepath |
Path in which the dataset, in .xlsx format, is stored.. |
df |
Foods dataframe. |
diets |
Chosen diets. Constraint sheets in foods dataset must be of format 'constraints_DIETNAME_diet_foods', then the parameter passed will be DIETNAME. Can be a vector of diets in format c('DIETNAME1','DIETNAME2',...,'DIETNAMEN'). |
max_scale |
Maximum scale. |
override_min |
If is not null, overrides all minimum values. |
Foods dataframe with constraints columns.
Adds emission data to foods dataframe.
addEmissionData(filepath, df, emission_cols = NULL)addEmissionData(filepath, df, emission_cols = NULL)
filepath |
Path in which the dataset, in .xlsx format, is stored. |
df |
Foods dataframe. |
emission_cols |
Optional parameter. Emission column names if standard dataset isn't used. |
Food dataframe with emission data.
Adds serves constraints to food groups dataframe
addFoodGroupsConstraintData(filepath, df, diets)addFoodGroupsConstraintData(filepath, df, diets)
filepath |
Path in which the dataset, in .xlsx format, is stored.. |
df |
Food groups dataframe. |
diets |
Chosen diets. Constraint sheets in foods dataset must be of format 'constraints_DIETNAME_diet_food_groups', then the parameter passed will be DIETNAME. Can be a vector of diets in format c('DIETNAME1','DIETNAME2',...,'DIETNAMEN'). |
Food groups dataframe with added constraint data.
Adds nutrients data to foods dataframe.
addNutrientData(filepath, df)addNutrientData(filepath, df)
filepath |
Path in which the dataset, in .xlsx format, is stored.. |
df |
Foods dataframe. |
Foods dataframe with nutrient columns.
Adds price data to foods dataframe.
addPriceData(filepath, df)addPriceData(filepath, df)
filepath |
Path in which the dataset, in .xlsx format, is stored.. |
df |
Foods dataframe. |
Foods dataframe with added price data.
Calculates a confidence interval for price and footprints obtained through a Monte Carlo Simulation, grouped by food groups. This function should be employed only if the standard table supplied with this package is utilized. Prints a .xlsx file in the home directory.
calculateGroupedResults(path_file, report_path, confidence_interval)calculateGroupedResults(path_file, report_path, confidence_interval)
path_file |
A string containing the path to the folder containing the .csv files created in the monteCarlo function. |
report_path |
A string containing the path to where the report will be saved. |
confidence_interval |
A float. Must be either 0.01, 0.05 or 0.1. |
No R object return, prints an Excel workbook.
Calculates a confidence interval for several parameters obtained through a Monte Carlo Simulation. This function should be employed only if the standard table supplied with this package is utilized. Prints a .xlsx file in the home directory.
calculateResults(path_file, report_path, confidence_interval)calculateResults(path_file, report_path, confidence_interval)
path_file |
A string containing the path to the folder containing the .csv files created in the monteCarlo function. |
report_path |
A string containing the path to where the report will be saved. |
confidence_interval |
A float. Must be either 0.01, 0.05 or 0.1. |
No R object return, prints an Excel workbook.
Checks if there are any missing values in a given column from the dataset.
check_function(name, column)check_function(name, column)
name |
Column in which missing values will be sought. |
column |
Column name, in string format. |
No return, only performs a check.
Checks if a given food has an ID assigned but is absent in another dataset.
check_id_defined(df1, df2, value)check_id_defined(df1, df2, value)
df1 |
First dataframe. |
df2 |
Second dataframe. |
value |
Dataset name. |
No return, only performs a check.
Checks if all foods have a price.
check_match_food_price(df)check_match_food_price(df)
df |
Dataframe. |
No return, only performs a check.
Checks if all individuals have a matching diet.
check_match_individual_diet(df)check_match_individual_diet(df)
df |
Dataframe. |
No return, only performs a check.
Looks for a minimum value and sets zero if missing,
check_min_exists(df, check, col)check_min_exists(df, check, col)
df |
Dataframe. |
check |
Boolean variable to permit optional food group. |
col |
Minimum percentage intake column name. |
Dataframe.
Checks if values supposed to be numeric are in fact numeric.
check_nom_num_df(df)check_nom_num_df(df)
df |
Dataframe columns. |
No return, only performs a check.
Checks if values supposed to be numeric are in fact numeric.
check_non_num(df)check_non_num(df)
df |
Dataframe column. |
No return, only performs a check.
Checks if two datasets have the same spelling in names column.
check_spelling(df1, df2, condition)check_spelling(df1, df2, condition)
df1 |
First dataframe. |
df2 |
Second dataframe. |
condition |
Column to be joined. |
No return, only performs a check.
Checks if varieties are into the allowed range (1,2 or 3).
check_variety(df)check_variety(df)
df |
Dataframe variety column. |
No return, only performs a check.
Checks if lower bound linked foods serves are lower or equal to higher bound linked foods serves.
checkLinkedFoods(df, low, high)checkLinkedFoods(df, low, high)
df |
Random meal plan. |
low |
Vector of lower bound food IDs. |
high |
Vector of higher bound food IDs. |
Differences dataframe.
If discretionary foods, alcohol or takeaway are permitted, looks for a minimum value and sets zero if missing,
checks_optional_food_groups(check, value)checks_optional_food_groups(check, value)
check |
Boolean variable to permit optional food group. |
value |
Minimum percentage of energy intake from optional food group. |
Minimum percentage of energy intake from optional food group.
Checks if differences dataframe is all zeroes.
checkZeroDiff(diff)checkZeroDiff(diff)
diff |
Differences dataframe |
Boolean. TRUE if all zeroes, FALSE otherwise.
Converts data from daily to weekly
converts_dataframe(df, exclusion_cols)converts_dataframe(df, exclusion_cols)
df |
Dataframe. |
exclusion_cols |
Columns (non-numerical or percentage) that conversion won't be applied. |
Weekly dataframe.
Converts food group serves dataframe to weekly values.
convertWeeklyFoodGroups(df, diet, individual)convertWeeklyFoodGroups(df, diet, individual)
df |
Food group serves dataframe. |
diet |
Chosen diet. Must be DIETNAME from 'constraints_DIETNAME_diet_food_groups' sheet in dataset. |
individual |
Individual whose random meal plan will be created to. Can be one of man, woman, boy or girl. |
Converted food group serves dataframe.
food_groups_wk <- convertWeeklyFoodGroups(DIETCOST::food_groups, 'C', 'man');food_groups_wk <- convertWeeklyFoodGroups(DIETCOST::food_groups, 'C', 'man');
Converts nutrient targets dataframe to weekly values.
convertWeeklyNutrientTargets(df, diet, person, nutrient_constraints = NULL)convertWeeklyNutrientTargets(df, diet, person, nutrient_constraints = NULL)
df |
Nutrient targets dataframe. |
diet |
Chosen diet. Must be DIETNAME from 'constraints_DIETNAME_diet_foods' sheet in dataset. |
person |
Individual whose random meal plan will be created to. Can be one of man, woman, boy or girl. |
nutrient_constraints |
Optional parameter. Vector of nutrients column names to be used if not all nutrients are to be used as constraints. |
Converted nutrient targets dataframe.
nutrient_targets_wk <- convertWeeklyNutrientTargets(DIETCOST::nutrient_targets, 'C', 'man')nutrient_targets_wk <- convertWeeklyNutrientTargets(DIETCOST::nutrient_targets, 'C', 'man')
Creates a food data dataframe
createFoodData(filepath, redmeat_ids)createFoodData(filepath, redmeat_ids)
filepath |
Path in which the dataset, in .xlsx format, is stored. |
redmeat_ids |
Vector of redmeat IDs. |
Food dataframe.
Creates and populates a food group data dataframe
createFoodGroupData(df)createFoodGroupData(df)
df |
Foods dataframe. |
Food group dataframe.
Adds nutrients data to foods dataframe.
createNutrientTargets( filepath, allow_alcohol = TRUE, allow_discretionary = TRUE, allow_takeaway = TRUE, alcohol_perc_max = NULL, discretionary_perc_max = NULL, takeaway_perc_max = NULL )createNutrientTargets( filepath, allow_alcohol = TRUE, allow_discretionary = TRUE, allow_takeaway = TRUE, alcohol_perc_max = NULL, discretionary_perc_max = NULL, takeaway_perc_max = NULL )
filepath |
Path in which the dataset, in .xlsx format, is stored.. |
allow_alcohol |
Boolean variable checking if alcohol is permitted. Default TRUE. |
allow_discretionary |
Boolean variable checking if discretionary foods are permitted. Default TRUE. |
allow_takeaway |
Boolean variable checking if takeaway is permitted. Default TRUE. |
alcohol_perc_max |
Optional parameter. Defines maximum energy intake derived from alcohol. |
discretionary_perc_max |
Optional parameter. Defines maximum energy intake derived from discretionary foods. |
takeaway_perc_max |
Optional parameter. Defines maximum energy intake derived from takeaway. |
Nutrient targets dataframe.
Creates a random meal plan.
createRandomMeal( foods_df, targets_df, person, diet, allowed_varieties, min_serve_size_difference, allow_discretionary = TRUE, allow_alcohol = TRUE, allow_takeaway = TRUE, emission_cols = NULL, nutrient_cols = NULL )createRandomMeal( foods_df, targets_df, person, diet, allowed_varieties, min_serve_size_difference, allow_discretionary = TRUE, allow_alcohol = TRUE, allow_takeaway = TRUE, emission_cols = NULL, nutrient_cols = NULL )
foods_df |
Foods dataframe. |
targets_df |
Nutrient targets dataframe. |
person |
Individual whose random meal plan will be created to. Can be one of man, woman, boy or girl. |
diet |
Chosen diet. Must be DIETNAME from 'constraints_DIETNAME_diet_foods' sheet in dataset. |
allowed_varieties |
Permitted food varieties. Can be a vector of the following: 1,2 and/or 3. |
min_serve_size_difference |
Multiplier to serve difference. A float between 0 and 1. |
allow_discretionary |
Boolean variable checking if discretionary foods are permitted. Default TRUE. |
allow_alcohol |
Boolean variable checking if alcohol is permitted. Default TRUE. |
allow_takeaway |
Boolean variable checking if takeaway is permitted. Default TRUE. |
emission_cols |
Optional parameter. Emission column names if standard dataset isn't used. |
nutrient_cols |
Optional parameter. Nutrients column names if standard dataset isn't used. |
Random meal plan dataframe.
foods_df <- createRandomMeal(foods_df = DIETCOST::foods, targets_df = DIETCOST::nutrient_targets, person = 'man', diet = 'C', allowed_varieties = c(1,2,3), min_serve_size_difference = 0.5, allow_takeaway = TRUE, allow_alcohol = TRUE, allow_discretionary = TRUE)foods_df <- createRandomMeal(foods_df = DIETCOST::foods, targets_df = DIETCOST::nutrient_targets, person = 'man', diet = 'C', allowed_varieties = c(1,2,3), min_serve_size_difference = 0.5, allow_takeaway = TRUE, allow_alcohol = TRUE, allow_discretionary = TRUE)
Calculates difference between values of random meal plan created and targets logged.
diff_calc(val, min, max)diff_calc(val, min, max)
val |
Value to be evalueted. |
min |
Minimum constraint. |
max |
Maximum constraint. |
Difference.
Converts energy values in megajoules (MJ) to kilojoules (KJ),
energy_conversor(df, min, max)energy_conversor(df, min, max)
df |
Dataframe. |
min |
Minimum energy column name. Default 'energy_mj_min'. |
max |
Maximum energy column name. Default 'energy_mj_max'. |
No return, only performs a check.
A set of data containing commonly available food groups based on a Brazilian typical diet.
food_groupsfood_groups
A dataframe with 12 rows and 74 columns:
Food group, i.e. 'Fruit' or 'Vegetable'
Numerical code for dood group
Weekly minimal current diet intake for males, in grams
Weekly maximal current diet intake for males, in grams
Weekly target current diet intake for males, in grams
Weekly minimal current diet intake for males, in serves
Weekly maximal current diet intake for males, in serves
Weekly target current diet intake for males, in serves
Weekly minimal current diet intake for females, in grams
Weekly maximal current diet intake for females, in grams
Weekly target current diet intake for females, in grams
Weekly minimal current diet intake for females, in serves
Weekly maximal current diet intake for females, in serves
Weekly target current diet intake for females, in serves
Weekly minimal current diet intake for boys, in grams
Weekly maximal current diet intake for boys, in grams
Weekly target current diet intake for boys, in grams
Weekly minimal current diet intake for boys, in serves
Weekly maximal current diet intake for boys, in serves
Weekly target current diet intake for boys, in serves
Weekly minimal current diet intake for girls, in grams
Weekly maximal current diet intake for girls, in grams
Weekly target current diet intake for girls, in grams
Weekly minimal current diet intake for girls, in serves
Weekly maximal current diet intake for girls, in serves
Weekly target current diet intake for girls, in serves
Weekly minimal EAT-Lancet diet intake for males, in grams
Weekly maximal EAT-Lancet diet intake for males, in grams
Weekly target EAT-Lancet diet intake for males, in grams
Weekly minimal EAT-Lancet diet intake for males, in serves
Weekly maximal EAT-Lancet diet intake for males, in serves
Weekly target EAT-Lancet diet intake for males, in serves
Weekly minimal EAT-Lancet diet intake for females, in grams
Weekly maximal EAT-Lancet diet intake for females, in grams
Weekly target EAT-Lancet diet intake for females, in grams
Weekly minimal EAT-Lancet diet intake for females, in serves
Weekly maximal EAT-Lancet diet intake for females, in serves
Weekly target EAT-Lancet diet intake for females, in serves
Weekly minimal EAT-Lancet diet intake for boys, in grams
Weekly maximal EAT-Lancet diet intake for boys, in grams
Weekly target EAT-Lancet diet intake for boys, in grams
Weekly minimal EAT-Lancet diet intake for boys, in serves
Weekly maximal EAT-Lancet diet intake for boys, in serves
Weekly target EAT-Lancet diet intake for boys, in serves
Weekly minimal EAT-Lancet diet intake for girls, in grams
Weekly maximal EAT-Lancet diet intake for girls, in grams
Weekly target EAT-Lancet diet intake for girls, in grams
Weekly minimal EAT-Lancet diet intake for girls, in serves
Weekly maximal EAT-Lancet diet intake for girls, in serves
Weekly target EAT-Lancet diet intake for girls, in serves
Weekly minimal healthy diet intake for males, in grams
Weekly maximal healthy diet intake for males, in grams
Weekly target healthy diet intake for males, in grams
Weekly minimal healthy diet intake for males, in serves
Weekly maximal healthy diet intake for males, in serves
Weekly target healthy diet intake for males, in serves
Weekly minimal healthy diet intake for females, in grams
Weekly maximal healthy diet intake for females, in grams
Weekly target healthy diet intake for females, in grams
Weekly minimal healthy diet intake for females, in serves
Weekly maximal healthy diet intake for females, in serves
Weekly target healthy diet intake for females, in serves
Weekly minimal healthy diet intake for boys, in grams
Weekly maximal healthy diet intake for boys, in grams
Weekly target healthy diet intake for boys, in grams
Weekly minimal healthy diet intake for boys, in serves
Weekly maximal healthy diet intake for boys, in serves
Weekly target healthy diet intake for boys, in serves
Weekly minimal healthy diet intake for girls, in grams
Weekly maximal healthy diet intake for girls, in grams
Weekly target healthy diet intake for girls, in grams
Weekly minimal healthy diet intake for girls, in serves
Weekly maximal healthy diet intake for girls, in serves
Weekly target healthy diet intake for girls, in serves
Elaborated by authors.
Creates foods dataframe, with emission, nutrients, constraints and price data, in a single function.
foodData( filepath = filepath, redmeat_ids, diets, max_scale, emission_cols = NULL, override_min = NULL )foodData( filepath = filepath, redmeat_ids, diets, max_scale, emission_cols = NULL, override_min = NULL )
filepath |
Path in which the dataset, in .xlsx format, is stored.. |
redmeat_ids |
Vector of unique food IDs that are redmeat. |
diets |
Chosen diets. Constraint sheets in foods dataset must be of format 'constraints_DIETNAME_diet_foods', then the parameter passed will be DIETNAME. Can be a vector of diets in format c('DIETNAME1','DIETNAME2',...,'DIETNAMEN'). |
max_scale |
Maximum scale. Default is two. |
emission_cols |
Optional parameter. Emission column names if standard dataset isn't used. |
override_min |
If is not null, overrides all minimum values |
Foods dataframe.
Creates food groups dataframe, with constraints data, in a single function.
foodGroupData(filepath, df_foods, diets)foodGroupData(filepath, df_foods, diets)
filepath |
Path in which the dataset, in .xlsx format, is stored. |
df_foods |
Foods dataframe. |
diets |
Chosen diets. Constraint sheets in foods dataset must be of format 'constraints_DIETNAME_diet_food_groups', then the parameter passed will be DIETNAME. Can be a vector of diets in format c('DIETNAME1','DIETNAME2',...,'DIETNAMEN'). |
Food groups dataframe.
A set of data containing commonly available foods based on a Brazilian typical diet.
foodsfoods
A dataframe with 99 rows and 45 columns:
Food group, i.e. 'Fruit' or 'Vegetable'
Numerical code for dood group
Food name, i.e. LEMON
Unique numerical food id
Variety. Must be 1, 2 or 3
Boolean redmeat identifier
Carbon footprint
Water footprint
Ecological footprint
Serve size for current diet, in grams
Minimal current diet intake for males, in grams
Minimal current diet intake for females, in grams
Minimal current diet intake for boys, in grams
Minimal current diet intake for girls, in grams
Maximal current diet intake for males, in grams
Maximal current diet intake for females, in grams
Maximal current diet intake for boys, in grams
Maximal current diet intake for girls, in grams
Serve size for EAT-Lancet diet, in grams
Minimal EAT-Lancet diet intake for males, in grams
Minimal EAT-Lancet diet intake for females, in grams
Minimal EAT-Lancet diet intake for boys, in grams
Minimal EAT-Lancet diet intake for girls, in grams
Maximal EAT-Lancet diet intake for males, in grams
Maximal EAT-Lancet diet intake for females, in grams
Maximal EAT-Lancet diet intake for boys, in grams
Maximal EAT-Lancet diet intake for girls, in grams
Serve size for healthy diet, in grams
Minimal healthy diet intake for males, in grams
Minimal healthy diet intake for females, in grams
Minimal healthy diet intake for boys, in grams
Minimal healthy diet intake for girls, in grams
Maximal healthy diet intake for males, in grams
Maximal healthy diet intake for females, in grams
Maximal healthy diet intake for boys, in grams
Maximal healthy diet intake for girls, in grams
Energy content of food, in kJ/g
Fat content of food per grams
Saturated fat content of food per grams
Carbohydrates content of food per grams
Sugars content of food per grams
Fibre content of food per grams
Protein content of food per grams
Sodium content of food per miligrams
Price of food per 100g
Elaborated by authors.
Applies difference calculation to entire dataset.
getDifference(df_target, df_nutrients, merge_col)getDifference(df_target, df_nutrients, merge_col)
df_target |
Constraints dataframe. |
df_nutrients |
Nutrients/serves from random meal plan dataframe. |
merge_col |
Column to join both dataframes. |
Differences dataframe.
Calculates total food group serves of random meal plan.
getFoodGroupServes(df)getFoodGroupServes(df)
df |
Random meal plan. |
Food group serves dataframe.
Calculates nutritional value of meal plan.
getNutrients(df, nutrient_cols = NULL)getNutrients(df, nutrient_cols = NULL)
df |
Random meal plan. |
nutrient_cols |
Optional parameter. Vector of nutrients column names to be used if nutrients are different from standard dataset. |
Nutrients dataframe.
Calculates percentage nutrient values.
getPerc(df_nutri, df_meal)getPerc(df_nutri, df_meal)
df_nutri |
Nutrient constraints dataframe. |
df_meal |
Random meal plan |
Percentage dataframe.
Safely performs a left join between two dataframes.
join_function(df1, df2, condition)join_function(df1, df2, condition)
df1 |
First dataframe. |
df2 |
Second dataframe. |
condition |
Column in which the two datframes will be joined. Can be a single string or a vector. |
Dataframe.
Creates a Monte Carlo simulation to a given number of iterations. A hit meal consists of one that returnz zero difference between nutrient targets and random meal plan, food groups serves and respects lower linked foods serves lower or equal to higher linked foods serves, if existent.
monteCarlo( dir_path, iterations, foods_df, nutrient_targets_df, food_group_targets_df, person, diet, allowed_varieties, min_serve_size_difference, allow_discretionary = TRUE, allow_alcohol = TRUE, allow_takeaway = TRUE, emission_cols = NULL, nutrient_cols = NULL, nutrient_constraints = NULL, linked_low_1 = NULL, linked_high_1 = NULL, linked_low_2 = NULL, linked_high_2 = NULL )monteCarlo( dir_path, iterations, foods_df, nutrient_targets_df, food_group_targets_df, person, diet, allowed_varieties, min_serve_size_difference, allow_discretionary = TRUE, allow_alcohol = TRUE, allow_takeaway = TRUE, emission_cols = NULL, nutrient_cols = NULL, nutrient_constraints = NULL, linked_low_1 = NULL, linked_high_1 = NULL, linked_low_2 = NULL, linked_high_2 = NULL )
dir_path |
A string containing the path where a directory will be created. |
iterations |
Number of iterations. Integer. |
foods_df |
Foods dataframe. |
nutrient_targets_df |
Nutrient constraints dataframe. |
food_group_targets_df |
Food group serves dataframe. |
person |
Individual whose random meal plan will be created to. Can be one of man, woman, boy or girl. |
diet |
Chosen diet. Must be DIETNAME from 'constraints_DIETNAME_diet_foods' sheet in dataset. |
allowed_varieties |
Permitted food varieties. Can be a vector of the following: 1,2 and/or 3. |
min_serve_size_difference |
Multiplier to serve difference. A float between 0 and 1. |
allow_discretionary |
Boolean variable checking if discretionary foods are permitted. Default TRUE. |
allow_alcohol |
Boolean variable checking if alcohol is permitted. Default TRUE. |
allow_takeaway |
Boolean variable checking if takeaway is permitted. Default TRUE. |
emission_cols |
Optional parameter. Emission column names if standard dataset isn't used. |
nutrient_cols |
Optional parameter. Nutrients column names if standard dataset isn't used. |
nutrient_constraints |
Optional parameter. Vector of nutrients column names to be used if not all nutrients are to be used as constraints. |
linked_low_1 |
Optional parameter. Vector of lower bound food IDs. |
linked_high_1 |
Optional parameter. Vector of higher bound food IDs. |
linked_low_2 |
Optional parameter. Vector of lower bound food IDs. |
linked_high_2 |
Optional parameter. Vector of higher bound food IDs. |
List of dataframes, containing results of simulation.
Runs Monte Carlo Simulation and prints results, in .xlsx format, in a single funtion.
monteCarloSimulation( dir_path, iterations, foods_df, nutrient_targets_df, food_group_targets_df, person, diet, allowed_varieties, min_serve_size_difference, allow_discretionary = TRUE, allow_alcohol = TRUE, allow_takeaway = TRUE, emission_cols = NULL, nutrient_cols = NULL, nutrient_constraints = NULL, linked_low_1 = NULL, linked_high_1 = NULL, linked_low_2 = NULL, linked_high_2 = NULL )monteCarloSimulation( dir_path, iterations, foods_df, nutrient_targets_df, food_group_targets_df, person, diet, allowed_varieties, min_serve_size_difference, allow_discretionary = TRUE, allow_alcohol = TRUE, allow_takeaway = TRUE, emission_cols = NULL, nutrient_cols = NULL, nutrient_constraints = NULL, linked_low_1 = NULL, linked_high_1 = NULL, linked_low_2 = NULL, linked_high_2 = NULL )
dir_path |
A string containing the path where a directory will be created. This same path will hold the reports Excel workbook. |
iterations |
Number of iterations. Integer. |
foods_df |
Foods dataframe. |
nutrient_targets_df |
Nutrient constraints dataframe. |
food_group_targets_df |
Food group serves dataframe. |
person |
Individual whose random meal plan will be created to. Can be one of man, woman, boy or girl. |
diet |
Chosen diet. Must be DIETNAME from 'constraints_DIETNAME_diet_foods' sheet in dataset. |
allowed_varieties |
Permitted food varieties. Can be a vector of the following: 1,2 and/or 3. |
min_serve_size_difference |
Multiplier to serve difference. A float between 0 and 1. |
allow_discretionary |
Boolean variable checking if discretionary foods are permitted. Default TRUE. |
allow_alcohol |
Boolean variable checking if alcohol is permitted. Default TRUE. |
allow_takeaway |
Boolean variable checking if takeaway is permitted. Default TRUE. |
emission_cols |
Optional parameter. Emission column names if standard dataset isn't used. |
nutrient_cols |
Optional parameter. Nutrients column names if standard dataset isn't used. |
nutrient_constraints |
Optional parameter. Vector of nutrients column names to be used if not all nutrients are to be used as constraints. |
linked_low_1 |
Optional parameter. Vector of lower bound food IDs. |
linked_high_1 |
Optional parameter. Vector of higher bound food IDs. |
linked_low_2 |
Optional parameter. Vector of lower bound food IDs. |
linked_high_2 |
Optional parameter. Vector of higher bound food IDs. |
No R object return. Prints an Excel workbook.
A set of data containing nutrient weekly targets based on a Brazilian typical diet.
nutrient_targetsnutrient_targets
A dataframe with 12 rows and 48 columns:
Person whose nutrient targets will be provided: man, woman, boy or girl
Diet whose nutrient targets will be provided: current (C), EAT-Lancet (PF) or healthy (H)
Minimal weekly intake of energy, in kJ/g
Maximal weekly intake of energy, in kJ/g
Minimal weekly intake of fat in grams
Maximal weekly intake of fat in grams
Minimal weekly intake of saturated fat in grams
Maximal weekly intake of saturated fat in grams
Minimal weekly intake of carbohydrates in grams
Maximal weekly intake of carbohydrates in grams
Minimal weekly intake of sugars in grams
Maximal weekly intake of sugars in grams
Minimal weekly intake of fibre in grams
Maximal weekly intake of fibre in grams
Minimal weekly intake of protein in grams
Maximal weekly intake of protein in grams
Minimal weekly intake of sodium in grams
Maximal weekly intake of sodium in grams
Minimal weekly intake of protein in percentage
Maximal weekly intake of protein in percentage
Minimal weekly intake of saturated fat in percentage
Maximal weekly intake of saturated fat in percentage
Minimal weekly intake of fat in percentage
Maximal weekly intake of fat in percentage
Minimal weekly intake of carbohydrates in percentage
Maximal weekly intake of carbohydrates in percentage
Minimal weekly intake of red meat in grams
Maximal weekly intake of red meat in grams
Minimal weekly intake of Fruit in serves
Maximal weekly intake of Fruit in serves
Minimal weekly intake of Starchy vegetables in serves
Maximal weekly intake of Starchy vegetables in serves
Minimal weekly intake of Vegetables in serves
Maximal weekly intake of Vegetables in serves
Minimal weekly intake of Dairy in serves
Maximal weekly intake of Dairy in serves
Minimal weekly intake of Grains in serves
Maximal weekly intake of Grains in serves
Minimal weekly intake of Protein in serves
Maximal weekly intake of Protein in serves
Minimal weekly intake of sugars in percentage
Maximal weekly intake of sugars in percentage
Minimal weekly intake of Alcohol in percentage
Maximal weekly intake of Alcohol in percentage
Minimal weekly intake of Discretionary foods in percentage
Maximal weekly intake of Discretionary foods in percentage
Minimal weekly intake of Takeaway in percentage
Maximal weekly intake of Takeaway foods in percentage
Elaborated by authors.
Applies nutrient data calculation to random meal plan generated.
nutrientDataCalculation(df, nutrient_cols = NULL)nutrientDataCalculation(df, nutrient_cols = NULL)
df |
Random meal plan. |
nutrient_cols |
Optional parameter. Nutrient column names if standard dataset isn't used. |
Random meal plan with nutrients calculated.
Checks if logged individuals are one or all of the following: man, woman, boy or girl.
permitted_individuals(df)permitted_individuals(df)
df |
Variable. |
No R object return, performs only a check.
Applies price and emission data calculation to random meal plan generated.
priceEmissionData(df, emission_cols = NULL)priceEmissionData(df, emission_cols = NULL)
df |
Random meal plan. |
emission_cols |
Optional parameter. Emission column names if standard dataset isn't used. |
Random meal plan with price and emissions calculated.
Exports, in .xlsx format, the results of Monte Carlo simulation.
printResults(file_path, results, person, diet, allowed_varieties, iterations)printResults(file_path, results, person, diet, allowed_varieties, iterations)
file_path |
A string containing the path where the file will be saved. |
results |
List of results |
person |
Individual whose random meal plan will be created to. Can be one of man, woman, boy or girl. |
diet |
Chosen diet. Must be DIETNAME from 'constraints_DIETNAME_diet_foods' sheet in dataset. |
allowed_varieties |
Permitted food varieties. Can be a vector of the following: 1,2 and/or 3. |
iterations |
Number of iterations. Integer. |
No R object return, prints a Excel workbook.
Randomly deletes a food.
random_plan(df, column, condition)random_plan(df, column, condition)
df |
Dataframe. |
column |
Column from which decision about removal of values will be made. |
condition |
Condition that, if is true, will enable radom removal. |
Random meal plan
Sets a boolean redmeat flag column in dataset.
redmeat_check(id, redmeat_ids)redmeat_check(id, redmeat_ids)
id |
Food group id column in dataframe. |
redmeat_ids |
Vector of unique food IDs that are redmeat. |
No R object return, performs only a check.
Removes one of two suffixes from column names
remove_suffix(vector, suffix_1, suffix_2)remove_suffix(vector, suffix_1, suffix_2)
vector |
Vector of column names |
suffix_1 |
First suffix to be removed. |
suffix_2 |
Second suffix to be removed. |
Vector of column names without suffixes.
Safely extracts a random unitary sample from a vector.
sample_safe(x)sample_safe(x)
x |
Vector. |
Random sample.
intake <- DIETCOST::sample_safe(c(10,25,37,52,100));intake <- DIETCOST::sample_safe(c(10,25,37,52,100));
Treats above said food name groups to the format used in the package.
sauces_protein_discretionary_change(group)sauces_protein_discretionary_change(group)
group |
Food group column in dataframe. |
Treated dataframe.
Checks if variable names are the standard defined into DIETCOST R standard table.
standard_name_check(df, ...)standard_name_check(df, ...)
df |
Dataframe. |
... |
Any number of strings. |
No R object return, performs only a check.
standard_name_check(DIETCOST::foods, 'food_id', 'food_name')standard_name_check(DIETCOST::foods, 'food_id', 'food_name')
Adds minimum and maximum serves of starchy vegetables.
starchy_fill(df, starchy_name, serve_identifier, max_identifier)starchy_fill(df, starchy_name, serve_identifier, max_identifier)
df |
Dataframe. |
starchy_name |
Starchy vegetables food group name. Default 'Starchy vegetables'. |
serve_identifier |
Serve column identifier. Default 'serve'. |
max_identifier |
Max column identifier. Default 'max'. |
Food group dataframe with starchy vegetable minimum and maximum serves columns added.
Pre-treatment of constraints dataframe.
treat_df(df, min_identifier, max_identifier, suffix, max_scale, override_min)treat_df(df, min_identifier, max_identifier, suffix, max_scale, override_min)
df |
Dataframe to be treated. |
min_identifier |
Minimum value column identifier. 'Min' in standard dataset. |
max_identifier |
Maximum value column identifier. 'Max' in standard dataset. |
suffix |
Suffix to be added to column name. |
max_scale |
Maximum scale. Default is two. |
override_min |
If is not null, overrides all minimum values. |
Treated dataframe.
Converts weekly food group serves to daily and adds diet suffix to column names.
treat_groups_df(df, suffix)treat_groups_df(df, suffix)
df |
Dataframe. |
suffix |
Suffix to be added to column. |
Treated food group dataframe.
Checks if there are non-unique values in dataset.
unique_values(value, df, value_col, value_name)unique_values(value, df, value_col, value_name)
value |
Column from which an unique vector will be formed. |
df |
Dataframe in which lies the column to be checked. |
value_col |
Name of the column to be checked, in string format. |
value_name |
Name of the variable tested. |
No R object return, performs only a check.
Safely uploads data to be processed in DIETCOST software.
upload_data(filepath, sheet)upload_data(filepath, sheet)
filepath |
The filepath in which the dataset, in .xlsx format, is saved. |
sheet |
The sheet of the .xlsx to be read. |
The dataframe generated by the file which was read.