4.4. Changing food quantities by nutrient amount

pantry features a --by-nut change option that will automatically change the quantity of a food so that it has a particular amount of a certain nutrient that you specify.[9] The --by-nut option takes two arguments. The first argument is a regular expression to match the nutrient you wish to use. The second argument is the amount of that nutrient that you wish the food to be set to. Let us look at an example:

Example 4.16. Using the --by-nut option

$ pantry --by-nut Calories 200 --name "Apples, raw, with skin" \
> --print traits-nuts master
Apples, raw, with skin
Group: Fruits and Fruit Juices
Refuse: 8 percent Core and stem
384.62 g (385g)
Nutrient                  Amount         %G     %TOT  
------------------------------------------------------
Calories                  200  kcal       10     100   
Total Fat                 1    g          1      100   
Saturated Fat             0    g          1      100   
Cholesterol               0    mg         0      NA    
Sodium                    4    mg         0      100   
Total Carbohydrate        53   g          18     100   
Dietary Fiber             9    g          37     100   
Sugars                    40   g          NG     100   
Protein                   1    g          2      100   
Vitamin A                 208  IU         4      100   
Vitamin C                 18   mg         29     100   
Calcium                   23   mg         2      100   
Iron                      0    mg         3      100   

As you can see, Pantry automatically changed the quantity of apples so that you would have 200 calories of apple. This works with any nutrient:

Example 4.17. Using --by-nut with Total Fat

$ pantry --by-nut "Total Fat" 5 --name "Avocados, raw, \
> California" --print traits-nuts master
Avocados, raw, California
Group: Fruits and Fruit Juices
Refuse: 33 percent Seed and skin
32.45 g (32g)
Nutrient                  Amount         %G     %TOT  
------------------------------------------------------
Calories                  54   kcal       3      100   
Total Fat                 5    g          8      100   
Saturated Fat             1    g          3      100   
Cholesterol               0    mg         0      NA    
Sodium                    3    mg         0      100   
Total Carbohydrate        3    g          1      100   
Dietary Fiber             2    g          9      100   
Sugars                    0    g          NG     100   
Protein                   1    g          1      100   
Vitamin A                 48   IU         1      100   
Vitamin C                 3    mg         5      100   
Calcium                   4    mg         0      100   
Iron                      0    mg         1      100   

That gave us the right number of grams of avocado that contain 5 grams of fat. The --by-nut also works with the --c-unit. For example, here is how you can find out what fraction of an avocado you would need to eat in order to consume 5 grams of fat:

Example 4.18. Using --by-nut with --c-unit

$ pantry --by-nut "Total Fat" 5 --name "Avocados, raw, \
> California" --c-unit fruit --print traits-nuts master
Avocados, raw, California
Group: Fruits and Fruit Juices
Refuse: 33 percent Seed and skin
0.24 fruit, without skin and seed (33g)
Nutrient                  Amount         %G     %TOT  
------------------------------------------------------
Calories                  55   kcal       3      100   
Total Fat                 5    g          8      100   
Saturated Fat             1    g          3      100   
Cholesterol               0    mg         0      NA    
Sodium                    3    mg         0      100   
Total Carbohydrate        3    g          1      100   
Dietary Fiber             2    g          9      100   
Sugars                    0    g          NG     100   
Protein                   1    g          1      100   
Vitamin A                 48   IU         1      100   
Vitamin C                 3    mg         5      100   
Calcium                   4    mg         0      100   
Iron                      0    mg         1      100   

The --by-nut option is useful in at least two circumstances. First, as we have already seen, it is useful if you are wondering how much of a food you need to consume in order to get a certain amount of a given nutrient. Second, it is useful if you wish to approximate intake of a food that is not already in the master file. For example, suppose I eat 1/2 of a cup of Stonyfield After Dark Chocolate ice cream.. Many brand-name foods are already in the master file, but this one is not. I look through the ice creams and find that the closest thing to Stonyfield in the master file is probably Ice creams, chocolate, rich:

Example 4.19. The closest thing to Stonyfield

$ pantry --exact-match --name "Ice creams, chocolate, rich" \
> --c-unit "cup" --c-qty .5 --print traits-nuts master
Ice creams, chocolate, rich
Group: Sweets
.5 cup (74g)
Nutrient                  Amount         %G     %TOT  
------------------------------------------------------
Calories                  189  kcal       9      100   
Total Fat                 13   g          19     100   
Saturated Fat             8    g          38     100   
Cholesterol               44   mg         15     100   
Sodium                    42   mg         2      100   
Total Carbohydrate        15   g          5      100   
Dietary Fiber             1    g          3      100   
Sugars                    13   g          NG     100   
Protein                   3    g          7      100   
Vitamin A                 528  IU         11     100   
Vitamin C                 0    mg         1      100   
Calcium                   105  mg         11     100   
Iron                      1    mg         4      100   

But Stonyfield apparently is even richer than this. 1/2 cup of Ice creams, chocolate, rich has 189 calories, but looking at the Stonyfield label tells me that 1/2 cup of Stonyfield has 250 calories. What should I do? Well, as we will learn in a later chapter, I can create a custom food for Stonyfield After Dark Chocolate ice cream. Or I might figure that Ice creams, chocolate, rich is close enough for our purposes. I can use it instead. My results will not be as accurate, but perhaps I am not feeling the need to be super accurate today. Because I know I ate 250 calories of Stonyfield, I just do this:

Example 4.20. Approximating one food by using another food and the --by-nut option

$ pantry --exact-match --name "Ice creams, chocolate, rich" \
> --by-nut Calories 250 --print traits-nuts master
Ice creams, chocolate, rich
Group: Sweets
98.04 g (98g)
Nutrient                  Amount         %G     %TOT  
------------------------------------------------------
Calories                  250  kcal       13     100   
Total Fat                 17   g          26     100   
Saturated Fat             10   g          51     100   
Cholesterol               59   mg         20     100   
Sodium                    56   mg         2      100   
Total Carbohydrate        20   g          7      100   
Dietary Fiber             1    g          4      100   
Sugars                    17   g          NG     100   
Protein                   5    g          9      100   
Vitamin A                 699  IU         14     100   
Vitamin C                 0    mg         1      100   
Calcium                   139  mg         14     100   
Iron                      1    mg         6      100   

If you compare Pantry's output to the Stonyfield label (available at the website) you will see that Pantry comes out fairly close to what is on the label.

The first argument--the nutrient name--is a regular expression. That means that it is case-sensitive, like all other regular expressions in Pantry, unless you use the --ignore-case option. Thus, --by-nut calories 250 will get you an error message unless you use --ignore-case but --by-nut Calories 250 will always work. This also allows you to shorten things a bit--for example, you can use --by-nut Saturated 250 to match Saturated Fat. In addition, the --by-nut also respects the --exact-match option, so if you are using --exact-match, then the first argument to --by-nut are not regular expressions and must exactly match the nutrient name.

Most commonly you would find yourself using --by-nut with Calories. Therefore, pantry has a -K option. It is equivalent to typing --by-nut Calories:

Example 4.21. Using the -K option

$ pantry --exact-match --name "Ice creams, chocolate, rich" -K \
> 250 --print traits-nuts master
Ice creams, chocolate, rich
Group: Sweets
98.04 g (98g)
Nutrient                  Amount         %G     %TOT  
------------------------------------------------------
Calories                  250  kcal       13     100   
Total Fat                 17   g          26     100   
Saturated Fat             10   g          51     100   
Cholesterol               59   mg         20     100   
Sodium                    56   mg         2      100   
Total Carbohydrate        20   g          7      100   
Dietary Fiber             1    g          4      100   
Sugars                    17   g          NG     100   
Protein                   5    g          9      100   
Vitamin A                 699  IU         14     100   
Vitamin C                 0    mg         1      100   
Calcium                   139  mg         14     100   
Iron                      1    mg         6      100   



[9] This feature shamelessly copied from a similar feature in NUT, as described under "Foods That Are Not in the Database" on How I Use NUT.