Skip to content

mikkelkrogsholm/NutrientData

Repository files navigation

This package contains data sets with the composition of Foods: Raw, Processed, Prepared. The source of the data is the USDA National Nutrient Database for Standard Reference, Release 28 (2015).

There are 12 data sets at the moment. 11 of them work as a relational database where the different data sets link to eachother. You can see how they link to eachother here:

The 12th data set is an abbreviated version of all the data called ABBREV. This is the easiest data set to begin with. And the one I will use in my example.

Basic nutrient information

# load NutrientData, dplyr and tidyr
library(NutrientData)
library(dplyr)
library(tidyr)

Lets first have a look at the the top 20 calorie dense foods

data("ABBREV") # Load the data

ABBREV %>% # Select the data
  arrange(-Energ_Kcal) %>% # Sort by calories per 100 g
  select(Food = Shrt_Desc, Calories = Energ_Kcal) %>% # Select relevant columns
  slice(1:20) %>% # Choose the top 20
  pander() # Make the table pretty-ish
Food Calories
FAT,BEEF TALLOW 902
LARD 902
FAT,MUTTON TALLOW 902
FISH OIL,COD LIVER 902
FISH OIL,HERRING 902
FISH OIL,MENHADEN 902
FISH OIL,MENHADEN,FULLY HYDR 902
FISH OIL,SALMON 902
FISH OIL,SARDINE 902
OIL,CORN,INDUSTRIAL & RTL,ALLPURP SALAD OR COOKING 900
FAT,CHICKEN 900
SHORTENING,HOUSEHOLD,LARD&VEG OIL 900
SHORTENING INDUSTRIAL,LARD&VEG OIL 900
SHORTENING FRYING (HVY DUTY),BF TALLOW&CTTNSD 900
FAT,TURKEY 900
FAT,GOOSE 900
OIL,INDUSTRIAL,CANOLA,HI OLEIC 900
OIL,INDUSTRIAL,SOY,LO LINOLENIC 900
OIL,BELUGA,WHALE (ALASKA NATIVE) 900
OIL,WALRUS (ALASKA NATIVE) 900

It's probably no big surprise that oil (pure fat) is the most calorie dense.

But what food contains the highest amount of protein? Lets have a look:

ABBREV %>% # Select the data
  arrange(-`Protein_(g)`) %>% # Sort by protein per 100 g
  select(Food = Shrt_Desc, Protein = `Protein_(g)`) %>% # Select relevant columns
  slice(1:20) %>% # Choose the top 20
  pander() # Make the table pretty-ish
Food Protein
SOY PROTEIN ISOLATE 88.32
SOY PROT ISOLATE,K TYPE 88.32
GELATINS,DRY PDR,UNSWTND 85.60
EGG,WHITE,DRIED,STABILIZED,GLUCOSE RED 84.08
SEAL,BEARDED (OOGRUK),MEAT,DRIED (ALASKA NATIVE) 82.60
EGG,WHITE,DRIED,PDR,STABILIZED,GLUCOSE RED 82.40
EGG,WHITE,DRIED 81.10
BEVERAGES,PROT PDR WHEY BSD 78.13
STEELHEAD TROUT,DRIED,FLESH (SHOSHONE BANNOCK) 77.27
EGG,WHITE,DRIED,FLAKES,STABILIZED,GLUCOSE RED 76.92
VITAL WHEAT GLUTEN 75.16
WHALE,BELUGA,MEAT,DRIED (ALASKA NATIVE) 69.86
BEVERAGES,ABBOTT,EAS WHEY PROT PDR 66.67
SOY PROT CONC,PRODUCED BY ALCOHOL EXTRACTION 63.63
SOY PROT CONC,PRODUCED BY ACID WASH 63.63
COD,ATLANTIC,DRIED&SALTED 62.82
FISH,WHITEFISH,DRIED (ALASKA NATIVE) 62.44
SEAL,BEARDED (OOGRUK),MEAT,PART DRIED (ALASKA NATIVE) 62.38
FISH,SALMON,CHUM,DRIED (ALASKA NATIVE) 62.09
PORK SKINS,PLAIN 61.30

Here we see that soy, eggwhites and pork skins are good sources of protein. Dig in!

Lets have a look at those pork skins and see what nutrients they contain:

ABBREV %>% # Select the data
  filter(Shrt_Desc == "PORK SKINS,PLAIN") %>% # Select the pork skins
  select(-1:-2) %>% # Remove name and number
  gather(Nutrients, Per_100_g) %>% # Turn into long format
  pander() # Make the table pretty-ish
Nutrients Per_100_g
Water_(g) 1.8
Energ_Kcal 544
Protein_(g) 61.3
Lipid_Tot_(g) 31.3
Ash_(g) 5.4
Carbohydrt_(g) 0
Fiber_TD_(g) 0
Sugar_Tot_(g) 0
Calcium_(mg) 30
Iron_(mg) 0.88
Magnesium_(mg) 11
Phosphorus_(mg) 85
Potassium_(mg) 127
Sodium_(mg) 1818
Zinc_(mg) 0.56
Copper_mg) 0.094
Manganese_(mg) 0.069
Selenium_(µg) 41
Vit_C_(mg) 0.5
Thiamin_(mg) 0.099
Riboflavin_(mg) 0.283
Niacin_(mg) 1.549
Panto_Acid_mg) 0.43
Vit_B6_(mg) 0.023
Folate_Tot_(µg) 0
Folic_Acid_(µg) 0
Food_Folate_(µg) 0
Folate_DFE_(µg) 0
Choline_Tot_ (mg) 164.5
Vit_B12_(µg) 0.64
Vit_A_IU 40
Vit_A_RAE 12
Retinol_(µg) 12
Alpha_Carot_(µg) 0
Beta_Carot_(µg) 0
Beta_Crypt_(µg) 0
Lycopene_(µg) 0
Lut+Zea_ (µg) 0
Vit_E_(mg) 0.53
Vit_D_µg 0
Vit_D_IU 0
Vit_K_(µg) 0
FA_Sat_(g) 11.37
FA_Mono_(g) 14.78
FA_Poly_(g) 3.64
Cholestrl_(mg) 95
GmWt_1 28.35
GmWt_Desc1 1 oz
GmWt_2 14.2
GmWt_Desc2 .5 oz
Refuse_Pct 0

Lookup and calculations

I have included a few functions to help do basic search and some nutrient calculations. The first one is search_ingredient(), which searches the ABBREV data based on one or more search strings.

Lets search for onion:

search_ingredient("onion")
#>  [1] "ONION POWDER"                                                
#>  [2] "SOUP,ONION,CND,COND"                                         
#>  [3] "SOUP,CRM OF ONION,CND,COND"                                  
#>  [4] "SOUP,ONION,DRY,MIX"                                          
#>  [5] "GRAVY,ONION,DRY,MIX"                                         
#>  [6] "PREGO PASTA,DICED ONION & GARLIC ITAL SAU,RTS"               
#>  [7] "SOUP,CRM OF ONION,CND,PREP W/ EQ VOLUME MILK"                
#>  [8] "CAMPBELL'S RED & WHITE,CRM OF ONION SOUP,COND"               
#>  [9] "CAMPBELL'S RED & WHITE,FRENCH ONION SOUP,COND"               
#> [10] "CAMPBELL'S CHUNKY SOUPS,SALISBURY STEAK MUSHRMS ONIONS SOUP" 
#> [11] "SOUP,CRM OF ONION,CND,PREP W/ EQ VOLUME H2O"                 
#> [12] "SOUP,ONION,DRY,MIX,PREP W/ H2O"                              
#> [13] "GRAVY,CAMPBELL'S,BROWN W/ ONIONS"                            
#> [14] "ONIONS,RAW"                                                  
#> [15] "ONIONS,CKD,BLD,DRND,WO/SALT"                                 
#> [16] "ONIONS,DEHYDRATED FLAKES"                                    
#> [17] "ONIONS,CND,SOL&LIQUIDS"                                      
#> [18] "ONIONS,YEL,SAUTEED"                                          
#> [19] "ONIONS,FRZ,CHOPD,UNPREP"                                     
#> [20] "ONIONS,FRZ,CHOPD,CKD,BLD,DRND,WO/SALT"                       
#> [21] "ONIONS,FRZ,WHL,UNPREP"                                       
#> [22] "ONIONS,FRZ,WHL,CKD,BLD,DRND,WO/SALT"                         
#> [23] "ONIONS,SPRING OR SCALLIONS (INCL TOPS&BULB),RAW"             
#> [24] "ONIONS,YOUNG GRN,TOPS ONLY"                                  
#> [25] "ONIONS,WELSH,RAW"                                            
#> [26] "ONIONS,SWT,RAW"                                              
#> [27] "ONION RINGS,BREADED,PAR FR,FRZ,UNPREP"                       
#> [28] "ONION RINGS,BREADED,PAR FR,FRZ,PREP,HTD IN OVEN"             
#> [29] "PEAS&ONIONS,CND,SOL&LIQUIDS"                                 
#> [30] "PEAS&ONIONS,FRZ,UNPREP"                                      
#> [31] "PEAS&ONIONS,FRZ,CKD,BLD,DRND,WO/SALT"                        
#> [32] "TOMATO PRODUCTS,CND,SAU,W/ONIONS"                            
#> [33] "TOMATO PRODUCTS,CND,SAU,W/ONIONS,GRN PEPPERS,&CELERY"        
#> [34] "ONIONS,CKD,BLD,DRND,W/SALT"                                  
#> [35] "ONIONS,FRZ,CHOPD,CKD,BLD,DRND,W/SALT"                        
#> [36] "ONIONS,FRZ,WHL,CKD,BLD,DRND,W/SALT"                          
#> [37] "PEAS&ONIONS,FRZ,CKD,BLD,DRND,W/SALT"                         
#> [38] "PICKLES,CHOWCHOW,W/CAULIFLOWER ONION MUSTARD,SWT"            
#> [39] "BAGEL,PLN,TSTD, ENR W/CA PROP(INCLUDE ONION,POPPY,SESAME)"   
#> [40] "BAGELS,PLN,ENR,W/ CA PROP (INCLUDES ONION,POPPY,SESAME),TSTD"
#> [41] "CRACKERS,MATZO,EGG&ONION"                                    
#> [42] "BAGELS,PLN,ENR,WO/CA PROP (INCL ONION,POPPY,SESAME)"         
#> [43] "BAGELS,PLN,UNENR,W/CA PROP (INCL ONION,POPPY,SESAME)"        
#> [44] "BAGELS,PLN,UNENR,WO/CA PROP (INCL ONION,POPPY,SESAME)"       
#> [45] "GEORGE WESTON BAKER,BROWNBERRY SAGE & ONION STUFFING MIX,DRY"
#> [46] "SNACKS,CORN-BASED,EXTRUDED,ONION-FLAVOR"                     
#> [47] "POTATO CHIPS,SOUR-CREAM-AND-ONION-FLAVOR"                    
#> [48] "POTATO CHIPS,MADE FR DRIED POTATOES,SOUR-CREAM&ONION-FLAVOR" 
#> [49] "FAST FOODS,ONION RINGS,BREADED&FRIED"                        
#> [50] "SUBWAY,SWT ONION CHICK SUB WHT BRD LTTC,TMT & SWT ONION SAU" 
#> [51] "FAST FOODS,SUB,SWT ONION CHICK WIT BRD W/ LTTC,TMT SWT ONION"
#> [52] "BURGER KING,ONION RINGS"                                     
#> [53] "SNACKS,FRITOLAY,SUNCHIPS,MULTIGRAIN,FRENCH ONION FLAVOR"     
#> [54] "KEEBLER,TOASTEDS,ONION CRACKERS"                             
#> [55] "KELLOGG'S,SPL K,CRACKER CHIPS,SOUR CRM & ONION"              
#> [56] "APPLEBEE'S,CRUNCHY ONION RINGS"                              
#> [57] "CRACKER BARREL,ONION RINGS,THICK-CUT"                        
#> [58] "DENNY'S,ONION RINGS"                                         
#> [59] "RESTAURANT,FAMILY STYLE,ONION RINGS"

As you can see, it returns all foods where it detects the word "onion". It's a bit too many. If you feed the function more words seperated by commas, it only returns the ones where all words match. Lets look for raw onions:

search_ingredient("onion,raw")
#> [1] "ONIONS,RAW"                                     
#> [2] "ONIONS,SPRING OR SCALLIONS (INCL TOPS&BULB),RAW"
#> [3] "ONIONS,WELSH,RAW"                               
#> [4] "ONIONS,SWT,RAW"

Much better. Only four results. We can know take the exact string of raw onions and feed it to the nutrient calculator, along with some cabbage and som mayonnaise.

In addition to telling it what foods we want to include in our calculations we also need to tell it how many grams we have of each.

ingredients <- c("CABBAGE,RAW", "MAYONNAISE,RED FAT,W/ OLIVE OIL", "ONIONS,RAW")
grams <- c(100, 20, 10)

calculate_nutrients(ingredients, grams) %>% 
  select(Food = 1, Calories = 3, Protein = 4,
         Fat = 5, Carbs = 7) %>% # Select only a few variables for looks and rename
  pander() # Make the table pretty-ish
Food Calories Protein Fat Carbs
CABBAGE,RAW 25 1.28 0.1 5.8
MAYONNAISE,RED FAT,W/ OLIVE OIL 72.2 0.074 8 0
ONIONS,RAW 4 0.11 0.01 0.934
TOTAL 101.2 1.464 8.11 6.734

So our little cabbage salad has a total of 101 calories coming mostly from the mayonnaise.

About

Contains the nutrient composition of foods: raw, processed and prepared

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages