Title: | R package supporting UMERTO LCA at KWB |
---|---|
Description: | Helper functions for data import, aggregation and visualisation of UMBERTO (https://www.ifu.com/umberto/) model output. |
Authors: | Michael Rustler [aut, cre] , Hauke Sonnenberg [ctb] , FAKIN [fnd], Kompetenzzentrum Wasser Berlin gGmbH (KWB) [cph] |
Maintainer: | Michael Rustler <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.2.0 |
Built: | 2024-10-31 05:52:25 UTC |
Source: | https://github.com/KWB-R/kwb.umberto |
Create pivot list
create_pivot_list(pivot_data, arrange_cols = "process")
create_pivot_list(pivot_data, arrange_cols = "process")
pivot_data |
privot data as retrieved from function pivot_data() |
arrange_cols |
columns used for arranging the data (default: "process") |
a list of results, where each element contains the result table for one lci_method
zipfile <- system.file("extdata/umberto-nxt_v7.1.0.13.503/Beispiel_Auswertung.zip", package = "kwb.umberto") umberto7_csv_dir <- file.path(tempdir(), "Beispiel_Auswertung") unzip(zipfile, exdir = umberto7_csv_dir) umberto7_rawdata <- kwb.umberto::import_rawdata(csv_dir = umberto7_csv_dir) umberto7_data_grouped <- kwb.umberto::group_data(umberto7_rawdata) umberto7_data_pivot <- kwb.umberto::pivot_data(umberto7_data_grouped) umberto7_data_pivot_list <- kwb.umberto::create_pivot_list(umberto7_data_pivot) head(umberto7_data_pivot_list) umberto10_csv_dir <- system.file("extdata/umberto-lca+_v10.1.0.3.146", package = "kwb.umberto") umberto10_rawdata <- kwb.umberto::import_rawdata(csv_dir = umberto10_csv_dir) umberto10_data_grouped <- kwb.umberto::group_data(umberto10_rawdata) umberto10_data_pivot <- kwb.umberto::pivot_data(umberto10_data_grouped) umberto10_data_pivot_list <- kwb.umberto::create_pivot_list(umberto10_data_pivot) head(umberto10_data_pivot_list)
zipfile <- system.file("extdata/umberto-nxt_v7.1.0.13.503/Beispiel_Auswertung.zip", package = "kwb.umberto") umberto7_csv_dir <- file.path(tempdir(), "Beispiel_Auswertung") unzip(zipfile, exdir = umberto7_csv_dir) umberto7_rawdata <- kwb.umberto::import_rawdata(csv_dir = umberto7_csv_dir) umberto7_data_grouped <- kwb.umberto::group_data(umberto7_rawdata) umberto7_data_pivot <- kwb.umberto::pivot_data(umberto7_data_grouped) umberto7_data_pivot_list <- kwb.umberto::create_pivot_list(umberto7_data_pivot) head(umberto7_data_pivot_list) umberto10_csv_dir <- system.file("extdata/umberto-lca+_v10.1.0.3.146", package = "kwb.umberto") umberto10_rawdata <- kwb.umberto::import_rawdata(csv_dir = umberto10_csv_dir) umberto10_data_grouped <- kwb.umberto::group_data(umberto10_rawdata) umberto10_data_pivot <- kwb.umberto::pivot_data(umberto10_data_grouped) umberto10_data_pivot_list <- kwb.umberto::create_pivot_list(umberto10_data_pivot) head(umberto10_data_pivot_list)
Group data
group_data( raw_data, grouping_paras = c("lci_method", "model", "process", "unit"), grouping_function = "sum", summarise_col = "quantity" )
group_data( raw_data, grouping_paras = c("lci_method", "model", "process", "unit"), grouping_function = "sum", summarise_col = "quantity" )
raw_data |
as retrieved by function import_rawdata() |
grouping_paras |
cleaned column names used for grouping. (default: c("lci_method", "model", "process", "unit")) |
grouping_function |
R function used for grouping (default: "sum") |
summarise_col |
column name used for summarising (default: "quantity"), i.e. for which the "grouping_function" should be applied |
aggregated data according
zipfile <- system.file("extdata/umberto-nxt_v7.1.0.13.503/Beispiel_Auswertung.zip", package = "kwb.umberto") umberto7_csv_dir <- file.path(tempdir(), "Beispiel_Auswertung") unzip(zipfile, exdir = umberto7_csv_dir) umberto7_rawdata <- kwb.umberto::import_rawdata(csv_dir = umberto7_csv_dir) umberto7_data_grouped <- kwb.umberto::group_data(umberto7_rawdata) head(umberto7_data_grouped ) umberto10_csv_dir <- system.file("extdata/umberto-lca+_v10.1.0.3.146", package = "kwb.umberto") umberto10_rawdata <- kwb.umberto::import_rawdata(csv_dir = umberto10_csv_dir) umberto10_data_grouped <- kwb.umberto::group_data(umberto10_rawdata) head(umberto10_data_grouped)
zipfile <- system.file("extdata/umberto-nxt_v7.1.0.13.503/Beispiel_Auswertung.zip", package = "kwb.umberto") umberto7_csv_dir <- file.path(tempdir(), "Beispiel_Auswertung") unzip(zipfile, exdir = umberto7_csv_dir) umberto7_rawdata <- kwb.umberto::import_rawdata(csv_dir = umberto7_csv_dir) umberto7_data_grouped <- kwb.umberto::group_data(umberto7_rawdata) head(umberto7_data_grouped ) umberto10_csv_dir <- system.file("extdata/umberto-lca+_v10.1.0.3.146", package = "kwb.umberto") umberto10_rawdata <- kwb.umberto::import_rawdata(csv_dir = umberto10_csv_dir) umberto10_data_grouped <- kwb.umberto::group_data(umberto10_rawdata) head(umberto10_data_grouped)
Import rawdata
import_rawdata(csv_dir, sep = ";", ...)
import_rawdata(csv_dir, sep = ";", ...)
csv_dir |
path to directory with .csv files |
sep |
Single character used to separate fields within a record (default: in GERMAN format, i.e. sep = ";") |
... |
further arguments passed to either readr::read_csv2 (default for sep == ';') or readr::read_csv (if sep == ',') |
data.frame with all imported raw data
zipfile <- system.file("extdata/umberto-nxt_v7.1.0.13.503/Beispiel_Auswertung.zip", package = "kwb.umberto") umberto7_csv_dir <- file.path(tempdir(), "Beispiel_Auswertung") unzip(zipfile, exdir = umberto7_csv_dir) umberto7_rawdata <- kwb.umberto::import_rawdata(csv_dir = umberto7_csv_dir) head(umberto7_rawdata) umberto10_csv_dir <- system.file("extdata/umberto-lca+_v10.1.0.3.146", package = "kwb.umberto") umberto10_rawdata <- kwb.umberto::import_rawdata(csv_dir = umberto10_csv_dir) head(umberto10_rawdata)
zipfile <- system.file("extdata/umberto-nxt_v7.1.0.13.503/Beispiel_Auswertung.zip", package = "kwb.umberto") umberto7_csv_dir <- file.path(tempdir(), "Beispiel_Auswertung") unzip(zipfile, exdir = umberto7_csv_dir) umberto7_rawdata <- kwb.umberto::import_rawdata(csv_dir = umberto7_csv_dir) head(umberto7_rawdata) umberto10_csv_dir <- system.file("extdata/umberto-lca+_v10.1.0.3.146", package = "kwb.umberto") umberto10_rawdata <- kwb.umberto::import_rawdata(csv_dir = umberto10_csv_dir) head(umberto10_rawdata)
Make pivot data
pivot_data( rawdata_grouped, cols_to_ignore = "unit", key_col = "model", value_col = "quantity_sum" )
pivot_data( rawdata_grouped, cols_to_ignore = "unit", key_col = "model", value_col = "quantity_sum" )
rawdata_grouped |
grouped rawdata as retrieved by function group_data() |
cols_to_ignore |
column names not to be considered for transforming the data from the "list" to the "wide" format with tidyr::spread() (default: "unit") |
key_col |
column name containing the key for transforming the data from the "list" to the "wide" format with tidyr::spread() (default: "model") |
value_col |
column name containing the values that will be used during transforming the data from the "list" to the "wide" format with tidyr::spread() (default: "quantity_sum") |
data.frame with the aggregated results for all different"lci_method"
zipfile <- system.file("extdata/umberto-nxt_v7.1.0.13.503/Beispiel_Auswertung.zip", package = "kwb.umberto") umberto7_csv_dir <- file.path(tempdir(), "Beispiel_Auswertung") unzip(zipfile, exdir = umberto7_csv_dir) umberto7_rawdata <- kwb.umberto::import_rawdata(csv_dir = umberto7_csv_dir) umberto7_data_grouped <- kwb.umberto::group_data(umberto7_rawdata) umberto7_data_pivot <- kwb.umberto::pivot_data(umberto7_data_grouped) head(umberto7_data_pivot) umberto10_csv_dir <- system.file("extdata/umberto-lca+_v10.1.0.3.146", package = "kwb.umberto") umberto10_rawdata <- kwb.umberto::import_rawdata(csv_dir = umberto10_csv_dir) umberto10_data_grouped <- kwb.umberto::group_data(umberto10_rawdata) umberto10_data_pivot <- kwb.umberto::pivot_data(umberto10_data_grouped) head(umberto10_data_pivot)
zipfile <- system.file("extdata/umberto-nxt_v7.1.0.13.503/Beispiel_Auswertung.zip", package = "kwb.umberto") umberto7_csv_dir <- file.path(tempdir(), "Beispiel_Auswertung") unzip(zipfile, exdir = umberto7_csv_dir) umberto7_rawdata <- kwb.umberto::import_rawdata(csv_dir = umberto7_csv_dir) umberto7_data_grouped <- kwb.umberto::group_data(umberto7_rawdata) umberto7_data_pivot <- kwb.umberto::pivot_data(umberto7_data_grouped) head(umberto7_data_pivot) umberto10_csv_dir <- system.file("extdata/umberto-lca+_v10.1.0.3.146", package = "kwb.umberto") umberto10_rawdata <- kwb.umberto::import_rawdata(csv_dir = umberto10_csv_dir) umberto10_data_grouped <- kwb.umberto::group_data(umberto10_rawdata) umberto10_data_pivot <- kwb.umberto::pivot_data(umberto10_data_grouped) head(umberto10_data_pivot)
Plot results
plot_results( grouped_data, x_col = "model", y_col = "quantity_sum", fill_col = "process" )
plot_results( grouped_data, x_col = "model", y_col = "quantity_sum", fill_col = "process" )
grouped_data |
data.frame with grouped rawdata as retrieved by function group_data() |
x_col |
column name to be used for plotting on x-axis (default: "model") |
y_col |
column name to be used for plotting on y-axis (default: "quantity_sum") |
fill_col |
column name to be used for filling (default: "process") |
simple plots for all different groups
zipfile <- system.file("extdata/umberto-nxt_v7.1.0.13.503/Beispiel_Auswertung.zip", package = "kwb.umberto") umberto7_csv_dir <- file.path(tempdir(), "Beispiel_Auswertung") unzip(zipfile, exdir = umberto7_csv_dir) umberto7_rawdata <- kwb.umberto::import_rawdata(csv_dir = umberto7_csv_dir) umberto7_data_grouped <- kwb.umberto::group_data(umberto7_rawdata) kwb.umberto::plot_results(grouped_data = umberto7_data_grouped) umberto10_csv_dir <- system.file("extdata/umberto-lca+_v10.1.0.3.146", package = "kwb.umberto") umberto10_rawdata <- kwb.umberto::import_rawdata(csv_dir = umberto10_csv_dir) umberto10_data_grouped <- kwb.umberto::group_data(umberto10_rawdata) kwb.umberto::plot_results(grouped_data = umberto10_data_grouped)
zipfile <- system.file("extdata/umberto-nxt_v7.1.0.13.503/Beispiel_Auswertung.zip", package = "kwb.umberto") umberto7_csv_dir <- file.path(tempdir(), "Beispiel_Auswertung") unzip(zipfile, exdir = umberto7_csv_dir) umberto7_rawdata <- kwb.umberto::import_rawdata(csv_dir = umberto7_csv_dir) umberto7_data_grouped <- kwb.umberto::group_data(umberto7_rawdata) kwb.umberto::plot_results(grouped_data = umberto7_data_grouped) umberto10_csv_dir <- system.file("extdata/umberto-lca+_v10.1.0.3.146", package = "kwb.umberto") umberto10_rawdata <- kwb.umberto::import_rawdata(csv_dir = umberto10_csv_dir) umberto10_data_grouped <- kwb.umberto::group_data(umberto10_rawdata) kwb.umberto::plot_results(grouped_data = umberto10_data_grouped)
Write results to EXCEL
write_xlsx(data_pivot_list, path = "results.xlsx")
write_xlsx(data_pivot_list, path = "results.xlsx")
data_pivot_list |
a list as retrieved by function create_pivot_list() |
path |
relative or full path to be used for exporting the results to EXCEL (default: "results.xlsx") |
writes results in EXCEL file defined in "path", where each sheet
zipfile <- system.file("extdata/umberto-nxt_v7.1.0.13.503/Beispiel_Auswertung.zip", package = "kwb.umberto") umberto7_csv_dir <- file.path(tempdir(), "Beispiel_Auswertung") unzip(zipfile, exdir = umberto7_csv_dir) umberto7_rawdata <- kwb.umberto::import_rawdata(csv_dir = umberto7_csv_dir) umberto7_data_grouped <- kwb.umberto::group_data(umberto7_rawdata) umberto7_data_pivot <- kwb.umberto::pivot_data(umberto7_data_grouped) umberto7_data_pivot_list <- kwb.umberto::create_pivot_list(umberto7_data_pivot) export_path <- file.path(getwd(), "umberto7_results.xlsx") print(sprintf("Exporting aggregated results to %s", export_path)) write_xlsx(umberto7_data_pivot_list, path = export_path) umberto10_csv_dir <- system.file("extdata/umberto-lca+_v10.1.0.3.146", package = "kwb.umberto") umberto10_rawdata <- kwb.umberto::import_rawdata(csv_dir = umberto10_csv_dir) umberto10_data_grouped <- kwb.umberto::group_data(umberto10_rawdata) umberto10_data_pivot <- kwb.umberto::pivot_data(umberto10_data_grouped) umberto10_data_pivot_list <- kwb.umberto::create_pivot_list(umberto10_data_pivot) export_path <- file.path(getwd(), "umberto10_results.xlsx") print(sprintf("Exporting aggregated results to %s", export_path)) write_xlsx(umberto10_data_pivot_list, path = export_path)
zipfile <- system.file("extdata/umberto-nxt_v7.1.0.13.503/Beispiel_Auswertung.zip", package = "kwb.umberto") umberto7_csv_dir <- file.path(tempdir(), "Beispiel_Auswertung") unzip(zipfile, exdir = umberto7_csv_dir) umberto7_rawdata <- kwb.umberto::import_rawdata(csv_dir = umberto7_csv_dir) umberto7_data_grouped <- kwb.umberto::group_data(umberto7_rawdata) umberto7_data_pivot <- kwb.umberto::pivot_data(umberto7_data_grouped) umberto7_data_pivot_list <- kwb.umberto::create_pivot_list(umberto7_data_pivot) export_path <- file.path(getwd(), "umberto7_results.xlsx") print(sprintf("Exporting aggregated results to %s", export_path)) write_xlsx(umberto7_data_pivot_list, path = export_path) umberto10_csv_dir <- system.file("extdata/umberto-lca+_v10.1.0.3.146", package = "kwb.umberto") umberto10_rawdata <- kwb.umberto::import_rawdata(csv_dir = umberto10_csv_dir) umberto10_data_grouped <- kwb.umberto::group_data(umberto10_rawdata) umberto10_data_pivot <- kwb.umberto::pivot_data(umberto10_data_grouped) umberto10_data_pivot_list <- kwb.umberto::create_pivot_list(umberto10_data_pivot) export_path <- file.path(getwd(), "umberto10_results.xlsx") print(sprintf("Exporting aggregated results to %s", export_path)) write_xlsx(umberto10_data_pivot_list, path = export_path)