knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

1 Install R packages

# Enable repository from kwb-r
options(repos = c(
  kwbr = 'https://kwb-r.r-universe.dev',
  CRAN = 'https://cloud.r-project.org'))

# Download and install kwb.umberto in R
install.packages('kwb.umberto')

2 Load the R package kwb.umberto

library(kwb.umberto)

3 Import data

3.1 Directory with example .csv files

The example .csv files (in German format, i.e. decimals are indicated with , and ; is used as field separator) were exported from Umberto NXT (v7.1.0.13.503) and attached to the R package kwb.umberto as shown below:

zipfile <- system.file("extdata/umberto-nxt_v7.1.0.13.503/Beispiel_Auswertung.zip", 
                       package = "kwb.umberto")
temp <- file.path(tempdir(), "Beispiel_Auswertung")
unzip(zipfile, exdir = temp)

dir(temp, pattern = ".csv")

3.2 Getting the data into R

Using the function kwb.umberto::import_rawdata() and specifying the parameter csv_dir = temp) imports the model results from one .csv file that is located in the folder r temp.

rawdata <- kwb.umberto::import_rawdata(csv_dir = temp)

To access the structure of the imported data one can run the following command:

head(rawdata)

3.3 Data aggregation

Once the data is imported into R, it can be aggregated as shown in the subsequent subchapters.

3.3.1 Grouping

data_grouped <- kwb.umberto::group_data(rawdata)
head(data_grouped)

3.3.2 Making pivot data

data_pivot <- kwb.umberto::pivot_data(data_grouped)
head(data_pivot)
data_pivot_list <- kwb.umberto::create_pivot_list(data_pivot)
head(data_pivot)

4 Data export

Finally the resulting data can be exported to an EXCEL spreatsheet. For each lci_method available in the imported dataset a sheet named lci_method_1 to lci_method_9 will be created, as there are 9 distinct lci_method available for this example data set:

r sprintf("\n- %s\n", unique(rawdata$lci_method))

export_path <- file.path(temp, "results.xlsx")
print(sprintf("Exporting aggregated results to %s", export_path))
write_xlsx(data_pivot_list, 
           path = export_path)

5 Data visualisation

In addition a simple visualisation of the imported and grouped data can be performed by calling the function kwb.umberto::plot_results() as shown below:

rawdata <- kwb.umberto::import_rawdata(csv_dir = temp)
data_grouped <- kwb.umberto::group_data(rawdata)
kwb.umberto::plot_results(grouped_data = data_grouped)


KWB-R/kwb.umberto documentation built on Dec. 12, 2022, 2:46 a.m.