Function Repository Resource:

NutritionReport

Source Notebook

Generate a nutrition report about foods specified in text

Contributed by: Isabel Skidmore, Gay Wilson and Tommy Peters

ResourceFunction["NutritionReport"][ingredients]

returns nutrition information for ingredients as a Dataset.

ResourceFunction["NutritionReport"][ingredients, format]

returns information in the specified format.

Details and Options

NutritionReport can handle a variety of input forms:
"ingredients"a single string, with different foods separated by a delimiting character (default "\n")
{"ingredient1","ingredient2",}a list of strings
{{"amount1","food1","note1"},}a list of lists of foods, amounts and notes, with each element given as a string

In the third form above, the "notei" parameters can be useful for tagging purposes, but do not affect numerical results.

The following values of format are accepted:
"Dataset"(default) returns nutrition as a Dataset
"Association"returns nutrition as a nested Association
"Table"returns nutrition as a nested List
"Tabular"returns nutrition as a Tabular object
"ASCIITable"returns nutrition as an ASCII table
The following options are accepted:
"DelimiterCharacter""\n"character used to separate ingredients within a single string
"NutritionProperties"{"AbsoluteTotalCaloriesContent","TotalFat", "TotalProtein","TotalCarbohydrates"}properties to be returned for each food
"RemoveAfterComma"Truewhether to trim any non-essential text after a comma for each food
"AdditionalFluff"{}additional strings to remove from food text to improve interpretation
An element of the "NutritionProperties" option value can be specified either as an expression of the form EntityProperty["Food" ,"standard name"], or as the bare string "standard name". A full list of available properties can be obtained by evaluating EntityValue["Food", "Properties"]

Examples

Basic Examples (1) 

Get nutrition information about the foods specified in a piece of text:

In[1]:=
ResourceFunction[
 "NutritionReport", ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"]["½ cup (1 stick) butter, at room temperature
1 cup sugar
2 eggs
2 cups all-purpose flour"]
Out[1]=

Scope (4) 

Get nutrition information as a nested Association:

In[2]:=
ResourceFunction[
 "NutritionReport", ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"][{"100g rice", "5oz grilled chicken"}, "Association"]
Out[2]=

Get nutrition information as a nested List:

In[3]:=
data = ResourceFunction[
  "NutritionReport", ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"][{"100g rice", "5oz grilled chicken"}, "Table"]
Out[3]=

Use TableForm to display this output with foods in columns and nutrition properties in rows:

In[4]:=
data // TableForm
Out[4]=

Get nutrition information as a Tabular object:

In[5]:=
ResourceFunction[
 "NutritionReport", ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"][{"100g rice", "5oz grilled chicken"}, "Tabular"]
Out[5]=

Get nutrition information as an ASCII table, with columns delimited by pipe characters ("|"):

In[6]:=
ResourceFunction[
 "NutritionReport", ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"][{"100g rice", "5oz grilled chicken"}, "ASCIITable"]
Out[6]=

Options (6) 

DelimiterCharacter (1) 

Use "DelimiterCharacter" to specify how to split up foods in a string:

In[7]:=
ResourceFunction[
 "NutritionReport", ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"]["1 egg; 200g sugar; 8 tbsp butter", "DelimiterCharacter" -> ";"]
Out[7]=

NutritionProperties (2) 

Specify the desired nutrition properties using the "NutritionProperties" option:

In[8]:=
ResourceFunction[
 "NutritionReport", ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"]["250g oats
100g sugar", "NutritionProperties" -> {EntityProperty["Food", "AbsoluteTotalCaloriesContent"], EntityProperty["Food", "AbsoluteTotalCarbohydratesContent"], EntityProperty["Food", "AbsoluteTotalFiberContent"]}]
Out[8]=

Lists of valid "Food" properties can be obtained using EntityValue:

In[9]:=
allFoodProperties = EntityValue["Food", "Properties"];
RandomSample[allFoodProperties, 5]
Out[10]=

Finding a particular property of interest can be simplified by querying particular EntityClass expressions:

In[11]:=
EntityValue["Food", "PropertyClasses"]
Out[11]=
In[12]:=
EntityValue[
 EntityPropertyClass["Food", "Macronutrients"], "Properties"]
Out[12]=

RemoveAfterComma (2) 

Use "RemoveAfterComma"False if there is important information to be retained after commas:

In[13]:=
ResourceFunction[
 "NutritionReport", ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"][{"100g rice", "5oz chicken, grilled"}, "RemoveAfterComma" -> False]
Out[13]=

The default setting "RemoveAfterComma"True ignores the preparation of the chicken in this example, and thus returns different results:

In[14]:=
ResourceFunction[
 "NutritionReport", ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"][{"100g rice", "5oz chicken, grilled"}]
Out[14]=

AdditionalFluff (1) 

There are some words that are filtered out of food strings by default as they are imprecise or do not impact nutrition (such as "lukewarm" in the example below). Use "AdditionalFluff" if there are additional strings that can be removed to improve interpretation (note that "fluff" strings are case-sensitive):

In[15]:=
ResourceFunction[
 "NutritionReport", ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"]["100g organic all-purpose flour
100ml lukewarm tap water", "AdditionalFluff" -> {"organic", "tap"}]
Out[15]=

Properties and Relations (1) 

NutritionReport uses Interpreter["Food"] internally to convert strings into computable "Food" entities:

In[16]:=
Interpreter["Food"]["Egg"]
Out[16]=
In[17]:=
%[EntityProperty["Food", "RelativeTotalFatContent"]]
Out[17]=

Possible Issues (6) 

More specific foods can be difficult to find data for:

In[18]:=
ResourceFunction[
  "NutritionReport", ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"][
  "8 oz lightly grilled thawed chicken breast with fat removed"] \.10
Out[18]=

Use simple strings with only necessary information to get better results:

In[19]:=
ResourceFunction[
 "NutritionReport", ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"]["8 oz grilled chicken breast"]
Out[19]=

Use options and specific input formats to help NutritionReport understand what information is essential:

In[20]:=
ResourceFunction[
 "NutritionReport", ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"][{{"8oz", "chicken breast", "lightly grilled, thawed, with fat removed"}}, "AdditionalFluff" -> "lightly"]
Out[20]=

Note that some "Food" properties are non-quantitative in nature. Using these in NutritionReport can cause errors:

In[21]:=
ResourceFunction[
 "NutritionReport", ResourceSystemBase -> "https://www.wolframcloud.com/obj/resourcesystem/api/1.0"]["1 egg, 1 carrot", "DelimiterCharacter" -> ",",
  "NutritionProperties" -> {EntityProperty["Food", "GeometryType"], EntityProperty["Food", "FiberLabel"]}]
Out[21]=

A large subset of strictly quantitative nutritional properties can be obtained as follows:

In[22]:=
Select[EntityValue["Food", "Properties"], StringContainsQ[Last@#, "content", IgnoreCase -> True] &];
RandomSample[%, 5]
Out[23]=

Some foods may not contain data for certain quantitative nutritional properties:

In[24]:=
EntityValue[Entity[
 "Food", {EntityProperty["Food", "FoodType"] -> ContainsExactly[{
Entity["FoodType", "Almond"]}], EntityProperty["Food", "AddedFoodTypes"] -> ContainsExactly[{}]}], EntityProperty["Food", "AsparticAcidContentPerItem"]]
Out[24]=

Requirements

Wolfram Language 13.0 (December 2021) or above

Version History

  • 1.1.0 – 20 October 2025
  • 1.0.0 – 14 April 2023

Related Resources

Author Notes

Other output formats that show nice reports, pie charts, etc. can be added with time. There is also endless tweaking to the string cleaning process that can be done; I have included common strings that I find to be irrelevant to nutrition but there could always be more. The more specific the default behavior is the less versatile, so I like to keep it flexible for users by using an option.

License Information