Skip to contents

Calculates VITA_RAEmcg_calculated = (RETOLmcg + (CARTBEQmcg_std/12)). Column names are case sensitive and an error is returned if not found. Non-numeric columns will be converted if possible in function to be numeric.

Usage

VITA_RAEmcg_calculator(
  df,
  RETOLmcg_column = "RETOLmcg",
  CARTBEQmcg_combined_column = "CARTBEQmcg_combined",
  comment = TRUE,
  comment_col = "comments"
)

Arguments

df

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

RETOLmcg_column

Required - default: 'RETOLmcg' - The name of the column containing Retinol in mcg per 100g of Edible Portion (EP).

CARTBEQmcg_combined_column

Required - default: 'CARTBEQmcg_combined' - Beta-carotene equivalents, in mcg per 100g of Edible Portion (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 calculation used to find the VITA_mcg_calculated value 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 comment is set to FALSE. If comment is set to TRUE, and the comment_col input is not the name of a column found in the df, the function will create a column with the name of the comment_col input to store comments in.

Value

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

Examples

# We will go through two examples of the VITA_RAEmcg_calculator, one using standard
# names, and another with non-standard names.
breakfast_df <- breakfast_df[,c("food_code", "food_name", "RETOLmcg",
"CARTBEQmcg_combined", "comments")]
breakfast_df
#>    food_code      food_name RETOLmcg CARTBEQmcg_combined
#> 1      F0001          Bacon       53                  NA
#> 2      F0002          Beans       12                  51
#> 3      F0003          Toast       20                  91
#> 4      F0004       Mushroom       NA                  22
#> 5      F0005           Eggs       62                  62
#> 6      F0006         Tomato       40                 102
#> 7      F0007        Sausage      140                  32
#> 8      F0008         Butter      210                  72
#> 9      F0009    Brown Sauce       41                 112
#> 10     F0010 Tomato Ketchup       NA                  NA
#>                          comments
#> 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

# This is the first data.frame; you can see it has the food item information,
# the required columns for calculation, and a comments column. Everything
# needed to run the VITA_RAEmcg_calculator.

VITA_RAE_results <- VITA_RAEmcg_calculator(breakfast_df)

VITA_RAE_results
#>    food_code      food_name RETOLmcg CARTBEQmcg_combined
#> 1      F0001          Bacon       53                  NA
#> 2      F0002          Beans       12                  51
#> 3      F0003          Toast       20                  91
#> 4      F0004       Mushroom       NA                  22
#> 5      F0005           Eggs       62                  62
#> 6      F0006         Tomato       40                 102
#> 7      F0007        Sausage      140                  32
#> 8      F0008         Butter      210                  72
#> 9      F0009    Brown Sauce       41                 112
#> 10     F0010 Tomato Ketchup       NA                  NA
#>                                                                                                                 comments
#> 1                                  VITA_RAEmcg_calculated value calculated from Retinol + 1/12 Beta-Carotene Equivalents
#> 2  These are imaginary food items; VITA_RAEmcg_calculated value calculated from Retinol + 1/12 Beta-Carotene Equivalents
#> 3                                  VITA_RAEmcg_calculated value calculated from Retinol + 1/12 Beta-Carotene Equivalents
#> 4  With imaginary nutrient values; VITA_RAEmcg_calculated value calculated from Retinol + 1/12 Beta-Carotene Equivalents
#> 5                                  VITA_RAEmcg_calculated value calculated from Retinol + 1/12 Beta-Carotene Equivalents
#> 6                      And blanks; VITA_RAEmcg_calculated value calculated from Retinol + 1/12 Beta-Carotene Equivalents
#> 7                                  VITA_RAEmcg_calculated value calculated from Retinol + 1/12 Beta-Carotene Equivalents
#> 8       To test different outputs; VITA_RAEmcg_calculated value calculated from Retinol + 1/12 Beta-Carotene Equivalents
#> 9                                  VITA_RAEmcg_calculated value calculated from Retinol + 1/12 Beta-Carotene Equivalents
#> 10                  And scenarios; VITA_RAEmcg_calculated value calculated from Retinol + 1/12 Beta-Carotene Equivalents
#>    VITA_RAEmcg_calculated
#> 1               53.000000
#> 2               16.250000
#> 3               27.583333
#> 4                1.833333
#> 5               67.166667
#> 6               48.500000
#> 7              142.666667
#> 8              216.000000
#> 9               50.333333
#> 10                     NA

# You can see how the data.frame has been returned with a new column (VITAmcg_calculated)
# and an additional comment in the comments column, detailing the calculation used.

# The second example uses non-standard names, to show how to set the input parameters
# if the data.frame is not using the suggested TAGNAMEunit naming system.

breakfast_df_nonstandard <- breakfast_df_nonstandard[,c("food_code",
"food_name", "Retinol_micrograms", "Beta_Carotene_Equivalents_micrograms",
"comments_column")]

breakfast_df_nonstandard
#>    food_code      food_name Retinol_micrograms
#> 1      F0001          Bacon                 53
#> 2      F0002          Beans                 12
#> 3      F0003          Toast                 20
#> 4      F0004       Mushroom                 NA
#> 5      F0005           Eggs                 62
#> 6      F0006         Tomato                 40
#> 7      F0007        Sausage                140
#> 8      F0008         Butter                210
#> 9      F0009    Brown Sauce                 41
#> 10     F0010 Tomato Ketchup                 NA
#>    Beta_Carotene_Equivalents_micrograms                comments_column
#> 1                                    NA                               
#> 2                                    51 These are imaginary food items
#> 3                                    91                           <NA>
#> 4                                    22 With imaginary nutrient values
#> 5                                    62                               
#> 6                                   102                     And blanks
#> 7                                    32                           <NA>
#> 8                                    72      To test different outputs
#> 9                                   112                               
#> 10                                   NA                  And scenarios
# You can see this is the same dataset as used previously, but with differing
# column names. This will mean the function will not know what the required
# column names are, and will need the user to name them.

VITA_RAE_results_nonstandard <- VITA_RAEmcg_calculator(breakfast_df_nonstandard,
RETOLmcg_column = "Retinol_micrograms",
CARTBEQmcg_combined_column = "Beta_Carotene_Equivalents_micrograms",
comment_col = "comments_column")

VITA_RAE_results_nonstandard
#>    food_code      food_name Retinol_micrograms
#> 1      F0001          Bacon                 53
#> 2      F0002          Beans                 12
#> 3      F0003          Toast                 20
#> 4      F0004       Mushroom                 NA
#> 5      F0005           Eggs                 62
#> 6      F0006         Tomato                 40
#> 7      F0007        Sausage                140
#> 8      F0008         Butter                210
#> 9      F0009    Brown Sauce                 41
#> 10     F0010 Tomato Ketchup                 NA
#>    Beta_Carotene_Equivalents_micrograms
#> 1                                    NA
#> 2                                    51
#> 3                                    91
#> 4                                    22
#> 5                                    62
#> 6                                   102
#> 7                                    32
#> 8                                    72
#> 9                                   112
#> 10                                   NA
#>                                                                                                          comments_column
#> 1                                  VITA_RAEmcg_calculated value calculated from Retinol + 1/12 Beta-Carotene Equivalents
#> 2  These are imaginary food items; VITA_RAEmcg_calculated value calculated from Retinol + 1/12 Beta-Carotene Equivalents
#> 3                                  VITA_RAEmcg_calculated value calculated from Retinol + 1/12 Beta-Carotene Equivalents
#> 4  With imaginary nutrient values; VITA_RAEmcg_calculated value calculated from Retinol + 1/12 Beta-Carotene Equivalents
#> 5                                  VITA_RAEmcg_calculated value calculated from Retinol + 1/12 Beta-Carotene Equivalents
#> 6                      And blanks; VITA_RAEmcg_calculated value calculated from Retinol + 1/12 Beta-Carotene Equivalents
#> 7                                  VITA_RAEmcg_calculated value calculated from Retinol + 1/12 Beta-Carotene Equivalents
#> 8       To test different outputs; VITA_RAEmcg_calculated value calculated from Retinol + 1/12 Beta-Carotene Equivalents
#> 9                                  VITA_RAEmcg_calculated value calculated from Retinol + 1/12 Beta-Carotene Equivalents
#> 10                  And scenarios; VITA_RAEmcg_calculated value calculated from Retinol + 1/12 Beta-Carotene Equivalents
#>    VITA_RAEmcg_calculated
#> 1               53.000000
#> 2               16.250000
#> 3               27.583333
#> 4                1.833333
#> 5               67.166667
#> 6               48.500000
#> 7              142.666667
#> 8              216.000000
#> 9               50.333333
#> 10                     NA

# You can see how the results are the same as calculated above, regardless of
# the changed column names.