packages <- c("knitr", "rebus", "tidyverse")
lapply(packages, require, character.only = T)
unit_conversions <- tibble(
application = c("US area conversion", "US old growth lumber volume conversion", "US metric volume conversion", "metric softwood density", "metric hardwood density", "US metric weight conversion", "US short tons conversion", "US volume conversion"),
value = c(144, 12, 35.3147, 433.57, 770, 2.2046, 907.185, 7.48052),
value_unit = c("sq_in", "bd_ft", "cu_ft", "kg", "kg", "kg", "kg", "gal"),
per = c("sq_ft", "cu_ft", "cu_m", "cu_m", "cu_m", "lbs", "US_ton", "cu_ft" ),
info_source = c("googUC", "googUC", "googUC", "awc.orgEPD", "awc.orgEPD", "googUC","googUC", "googUC")
)
# for convenience, add a couple more conversions that are derived from the values in the unit_conversions table defined above
# first add US volume (in cubic feet) conversions for the wood density factors (keeping in kilograms to match impact factor `declaredUnit`)
# the `dplyr::add_row()` function does not like to do calculations for assigning values to the fields, so initially the value is set to 0 then subsequent code lines do the math
unit_conversions <- unit_conversions %>%
add_row(application = "US metric softwood density",
value = 0,
value_unit = "kg",
per = "cu_ft",
info_source = "calculated"
) %>%
add_row(application = "US metric hardwood density",
value = 0,
value_unit = "kg",
per = "cu_ft",
info_source = "calculated"
)
# US metric softwood density value = metric softwood density value (kg per cu_m) / US metric volume conversion (cu_ft per cu_m)
unit_conversions[9,2] <- unit_conversions[4,2]/unit_conversions[3,2]
# US metric hardwood density value = metric hardwood density value (kg per cu_m) / US metric volume conversion (cu_ft per cu_m)
unit_conversions[10,2] <- unit_conversions[5,2]/unit_conversions[3,2]
# create the value_reciprocal column
unit_conversions$value_reciprocal <- 1/unit_conversions$value
unit_conversions <- unit_conversions[,c(1:4,6,5)]
View(unit_conversions)
