Skip to content

Commit

Permalink
Excel to be produced in R
Browse files Browse the repository at this point in the history
  • Loading branch information
SOloo15 committed Feb 21, 2024
1 parent 5bc436a commit 280c321
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ importFrom(dplyr,rename)
importFrom(dplyr,select)
importFrom(dplyr,summarise)
importFrom(jsonlite,toJSON)
importFrom(openxlsx,write.xlsx)
importFrom(stringr,str_detect)
importFrom(tidyr,gather)
importFrom(tidyr,spread)
Expand Down
6 changes: 6 additions & 0 deletions R/differences.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#'
#' @importFrom dplyr %>%
#'
#' @importFrom openxlsx write.xlsx
#'
#' @examples
#' \dontrun{
#' data(para)
Expand Down Expand Up @@ -171,4 +173,8 @@ calculate_differences <- function(outFile,...){

write(jsonlite::toJSON(results, pretty = TRUE),output_path)

# Save to Excel with multiple sheets
excel_output_path <- paste0(output_path, "/runs_comparison.xlsx") # Change this to your desired output path
write.xlsx(results, excel_output_path)

}
36 changes: 36 additions & 0 deletions R/merge_outputs.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#'
#' @importFrom jsonlite toJSON
#'
#' @importFrom openxlsx write.xlsx
#'
#' @examples
#' \dontrun{
#' data(para)
Expand Down Expand Up @@ -679,4 +681,38 @@ combineOutputs <- function(para, feed_basket_quality, energy_required, land_requ

jsonlite::toJSON(output_list, pretty = TRUE)

# Flatten the nested structure
df_land_required <- output_list$land_required$land_required
df_dm_required <- output_list$land_required$dm_required
df_land_and_dm_required <- output_list$land_required$land_and_dm_required
df_overall_soil_impact <- output_list$soil_impacts$overal_soil_impact
df_nitrogen_balance <- output_list$soil_impacts$nitrogen_balance
df_water_use_per_feed_item <- output_list$water_required$water_use_per_feed_item
df_water_use_for_production <- output_list$water_required$water_use_for_production
df_consumable_livestock_product <- output_list$livestock_productivity$consumable_livestock_product
df_manure_produced <- output_list$livestock_productivity$manure_produced
df_ghg_balance <- output_list$ghg_emission$ghg_balance
df_global_warming_potential <- output_list$ghg_emission$global_warming_potential
df_biomass <- output_list$biomass
df_soil_carbon <- output_list$soil_carbon
df_product_waste <- output_list$product_waste

# Save to Excel with multiple sheets
excel_output_path <- paste0(directoryPath, "/", fileName, ".xlsx") # Change this to your desired output path
write.xlsx(list("Land Required" = df_land_required,
"DM Required" = df_dm_required,
"Land and DM Required" = df_land_and_dm_required,
"Overall Soil Impact" = df_overall_soil_impact,
"Nitrogen Balance" = df_nitrogen_balance,
"Water Use Per Feed Item" = df_water_use_per_feed_item,
"Water Use For Production" = df_water_use_for_production,
"Consumable Livestock Product" = df_consumable_livestock_product,
"Manure Produced" = df_manure_produced,
"GHG Balance" = df_ghg_balance,
"Global Warming Potential" = df_global_warming_potential,
"Biomass" = df_biomass,
"Soil Carbon" = df_soil_carbon,
"Product Waste" = df_product_waste),
excel_output_path)

} #end of output function

0 comments on commit 280c321

Please sign in to comment.