Skip to contents

Combines possible values for Thiamine heirachically so the most suitable is the one used. Considers Thiamine and Thiamine Hydrochloride.

Usage

THIAmg_combiner(
  df,
  THIAmg_column = "THIAmg",
  THIAHCLmg_column = "THIAHCLmg",
  comment = TRUE,
  comment_col = "comments"
)

Arguments

df

Required - the data.frame the data is currently stored in.

THIAmg_column

Required - default: 'THIAmg' - The name of the column containing Thiamine, vitamin B1 analysed and expressed as Thiamine in mg per 100g of EP.

THIAHCLmg_column

Required - default: 'THIAHCLmg' - The name of the column containing THIAHCLmg hydrochloride, vitamin B1 analysed and expressed as Thiamine hydrochloride in mg per 100g of EP.

comment

Required - default: TRUE - TRUE or FALSE. If comment is set to TRUE (as it is by default), when the function is run a comment describing the source of the THIAmg_combined column is added to the comment_col. If no comment_col is selected, and comment = TRUE, one is created.

comment_col

Optional - default: 'comments' - A potential input variable; the column which contains the metadata comments for the food item in question. Not required if the comment parameter is set to FALSE. If set to true, and the comment_col entry is not found in the df, it will create a column with the name of the entry.

Value

Original data.frame with a new THIAmg_combined column, and (depending on the options selected) an additional comment/comments column and comment.

Examples

 #' # Two example data.frames have been created to give an example of
# using the THIAmg_combiner; one with the expected inputs, another with custom
# inputs.

breakfast_df <- breakfast_df[, c("food_code", "food_name", "THIAmg", "THIAHCLmg",
"comments")]
breakfast_df
#>    food_code      food_name THIAmg THIAHCLmg                       comments
#> 1      F0001          Bacon     32        21                               
#> 2      F0002          Beans     90        45 These are imaginary food items
#> 3      F0003          Toast    130        20                           <NA>
#> 4      F0004       Mushroom     21        69 With imaginary nutrient values
#> 5      F0005           Eggs   <NA>        42                               
#> 6      F0006         Tomato     61       150                     And blanks
#> 7      F0007        Sausage     21        23                           <NA>
#> 8      F0008         Butter               30      To test different outputs
#> 9      F0009    Brown Sauce     59        52                               
#> 10     F0010 Tomato Ketchup   <NA>        NA                  And scenarios

# We start with a data.frame containing patchy values between THIAmg and THIAHCLmg. Ideally
# we would like to combine these into a single 'combined' column with as few gaps
# as possible. This is the purpose of the THIAmg_combiner.

THIA_results <- THIAmg_combiner(breakfast_df)
#> ---------------------------
#> 
#> Breakdown of values used:
#> 
#> No suitable value for THIAmg_combined found 
#>                                           1 
#>          THIAmg_combined equal to THIAHCLmg 
#>                                           2 
#>             THIAmg_combined equal to THIAmg 
#>                                           7 
#> 
#> ---------------------------
THIA_results
#>    food_code      food_name THIAmg THIAHCLmg
#> 1      F0001          Bacon     32        21
#> 2      F0002          Beans     90        45
#> 3      F0003          Toast    130        20
#> 4      F0004       Mushroom     21        69
#> 5      F0005           Eggs   <NA>        42
#> 6      F0006         Tomato     61       150
#> 7      F0007        Sausage     21        23
#> 8      F0008         Butter               30
#> 9      F0009    Brown Sauce     59        52
#> 10     F0010 Tomato Ketchup   <NA>        NA
#>                                                           comments
#> 1                                  THIAmg_combined equal to THIAmg
#> 2  These are imaginary food items; THIAmg_combined equal to THIAmg
#> 3                                  THIAmg_combined equal to THIAmg
#> 4  With imaginary nutrient values; THIAmg_combined equal to THIAmg
#> 5                               THIAmg_combined equal to THIAHCLmg
#> 6                      And blanks; THIAmg_combined equal to THIAmg
#> 7                                  THIAmg_combined equal to THIAmg
#> 8    To test different outputs; THIAmg_combined equal to THIAHCLmg
#> 9                                  THIAmg_combined equal to THIAmg
#> 10      And scenarios; No suitable value for THIAmg_combined found
#>    THIAmg_combined
#> 1               32
#> 2               90
#> 3              130
#> 4               21
#> 5               42
#> 6               61
#> 7               21
#> 8               30
#> 9               59
#> 10            <NA>

# Note how there is now a new THIAmg_combined column, with values filled in
# from the THIAmg and THIAHCLmg columns, depending on which is most appropriate.
# A comment has also been added to the comments column detailing this change.

# This works without any input beyond the data.frame containing the nutrition
# information because the function is expecting standard column names, comprised
# of the nutrient INFOODS Tagname and the unit. However, if the columns are not
# named this way, then the user must specify which column relates to which input.
# An example of this is shown below.
breakfast_df_nonstandard <- breakfast_df_nonstandard[, c("food_code", "food_name",
 "Thiamine_milligrams", "Thiamine_from_HCL_milligrams", "comments_column")]
breakfast_df_nonstandard
#>    food_code      food_name Thiamine_milligrams Thiamine_from_HCL_milligrams
#> 1      F0001          Bacon                  32                           21
#> 2      F0002          Beans                  90                           45
#> 3      F0003          Toast                 130                           20
#> 4      F0004       Mushroom                  21                           69
#> 5      F0005           Eggs                <NA>                           42
#> 6      F0006         Tomato                  61                          150
#> 7      F0007        Sausage                  21                           23
#> 8      F0008         Butter                                               30
#> 9      F0009    Brown Sauce                  59                           52
#> 10     F0010 Tomato Ketchup                <NA>                           NA
#>                   comments_column
#> 1                                
#> 2  These are imaginary food items
#> 3                            <NA>
#> 4  With imaginary nutrient values
#> 5                                
#> 6                      And blanks
#> 7                            <NA>
#> 8       To test different outputs
#> 9                                
#> 10                  And scenarios

# You can see how the column names are different. The values remain the same
# however.

# To use these non-standard names, you must specify each input - as shown below.

THIA_results_nonstandard <- THIAmg_combiner(breakfast_df_nonstandard,
THIAmg_column = "Thiamine_milligrams",
THIAHCLmg_column = "Thiamine_from_HCL_milligrams",
comment_col = "comments_column")
#> ---------------------------
#> 
#> Breakdown of values used:
#> 
#> No suitable value for THIAmg_combined found 
#>                                           1 
#>          THIAmg_combined equal to THIAHCLmg 
#>                                           2 
#>             THIAmg_combined equal to THIAmg 
#>                                           7 
#> 
#> ---------------------------

THIA_results_nonstandard
#>    food_code      food_name Thiamine_milligrams Thiamine_from_HCL_milligrams
#> 1      F0001          Bacon                  32                           21
#> 2      F0002          Beans                  90                           45
#> 3      F0003          Toast                 130                           20
#> 4      F0004       Mushroom                  21                           69
#> 5      F0005           Eggs                <NA>                           42
#> 6      F0006         Tomato                  61                          150
#> 7      F0007        Sausage                  21                           23
#> 8      F0008         Butter                                               30
#> 9      F0009    Brown Sauce                  59                           52
#> 10     F0010 Tomato Ketchup                <NA>                           NA
#>                                                    comments_column
#> 1                                  THIAmg_combined equal to THIAmg
#> 2  These are imaginary food items; THIAmg_combined equal to THIAmg
#> 3                                  THIAmg_combined equal to THIAmg
#> 4  With imaginary nutrient values; THIAmg_combined equal to THIAmg
#> 5                               THIAmg_combined equal to THIAHCLmg
#> 6                      And blanks; THIAmg_combined equal to THIAmg
#> 7                                  THIAmg_combined equal to THIAmg
#> 8    To test different outputs; THIAmg_combined equal to THIAHCLmg
#> 9                                  THIAmg_combined equal to THIAmg
#> 10      And scenarios; No suitable value for THIAmg_combined found
#>    THIAmg_combined
#> 1               32
#> 2               90
#> 3              130
#> 4               21
#> 5               42
#> 6               61
#> 7               21
#> 8               30
#> 9               59
#> 10            <NA>

# You can see from the results that the calculation is run in exactly the same
# way, with the changed column names.