Calculates VITAmcg_calculated = (RETOLmcg + (CARTBEQmcg_combined/6)). Column names are case sensitive and an error is returned if not found.
Usage
VITAmcg_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
orFALSE
. Ifcomment
is set toTRUE
(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 thecomment_col
. If nocomment_col
is selected, andcomment = 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 ifcomment
is set toFALSE
. Ifcomment
is set toTRUE
, and thecomment_col
input is not the name of a column found in thedf
, the function will create a column with the name of thecomment_col
input to store comments in.
Value
Original data.frame with a new VITAmcg_calculated
column, and
(depending on the options selected) an additional comment/comments column
and comment.
Examples
# We will go through two examples of the VITAmcg_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 VITAmcg_calculator.
VitA_results <- VITAmcg_calculator(breakfast_df)
VitA_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 VITAmcg_calculated value calculated from Retinol + 1/6 Beta-Carotene Equivalents
#> 2 These are imaginary food items; VITAmcg_calculated value calculated from Retinol + 1/6 Beta-Carotene Equivalents
#> 3 VITAmcg_calculated value calculated from Retinol + 1/6 Beta-Carotene Equivalents
#> 4 With imaginary nutrient values; VITAmcg_calculated value calculated from Retinol + 1/6 Beta-Carotene Equivalents
#> 5 VITAmcg_calculated value calculated from Retinol + 1/6 Beta-Carotene Equivalents
#> 6 And blanks; VITAmcg_calculated value calculated from Retinol + 1/6 Beta-Carotene Equivalents
#> 7 VITAmcg_calculated value calculated from Retinol + 1/6 Beta-Carotene Equivalents
#> 8 To test different outputs; VITAmcg_calculated value calculated from Retinol + 1/6 Beta-Carotene Equivalents
#> 9 VITAmcg_calculated value calculated from Retinol + 1/6 Beta-Carotene Equivalents
#> 10 And scenarios; VITAmcg_calculated value calculated from Retinol + 1/6 Beta-Carotene Equivalents
#> VITAmcg_calculated
#> 1 53.000000
#> 2 20.500000
#> 3 35.166667
#> 4 3.666667
#> 5 72.333333
#> 6 57.000000
#> 7 145.333333
#> 8 222.000000
#> 9 59.666667
#> 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_results_nonstandard <- VITAmcg_calculator(breakfast_df_nonstandard,
RETOLmcg_column = "Retinol_micrograms",
CARTBEQmcg_combined_column = "Beta_Carotene_Equivalents_micrograms",
comment_col = "comments_column")
VitA_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 VITAmcg_calculated value calculated from Retinol + 1/6 Beta-Carotene Equivalents
#> 2 These are imaginary food items; VITAmcg_calculated value calculated from Retinol + 1/6 Beta-Carotene Equivalents
#> 3 VITAmcg_calculated value calculated from Retinol + 1/6 Beta-Carotene Equivalents
#> 4 With imaginary nutrient values; VITAmcg_calculated value calculated from Retinol + 1/6 Beta-Carotene Equivalents
#> 5 VITAmcg_calculated value calculated from Retinol + 1/6 Beta-Carotene Equivalents
#> 6 And blanks; VITAmcg_calculated value calculated from Retinol + 1/6 Beta-Carotene Equivalents
#> 7 VITAmcg_calculated value calculated from Retinol + 1/6 Beta-Carotene Equivalents
#> 8 To test different outputs; VITAmcg_calculated value calculated from Retinol + 1/6 Beta-Carotene Equivalents
#> 9 VITAmcg_calculated value calculated from Retinol + 1/6 Beta-Carotene Equivalents
#> 10 And scenarios; VITAmcg_calculated value calculated from Retinol + 1/6 Beta-Carotene Equivalents
#> VITAmcg_calculated
#> 1 53.000000
#> 2 20.500000
#> 3 35.166667
#> 4 3.666667
#> 5 72.333333
#> 6 57.000000
#> 7 145.333333
#> 8 222.000000
#> 9 59.666667
#> 10 NA
# You can see how the results are the same as calculated above, regardless of
# the changed column names.