Skip to content

Commit

Permalink
Use selectColumns(), add argument "method_col"
Browse files Browse the repository at this point in the history
  • Loading branch information
hsonne committed Sep 5, 2023
1 parent 0b7b58c commit fb57971
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Imports:
ggforce,
ggplot2,
janitor,
kwb.utils,
magrittr,
openxlsx,
readr,
Expand Down
17 changes: 12 additions & 5 deletions R/data_aggregation.R
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ pivot_data <- function(
#' @return a list of results, where each element contains the result table for
#' one lci_method
#' @importFrom dplyr right_join arrange
#' @importFrom kwb.utils selectColumns
#' @export
#' @examples
#'
Expand All @@ -126,23 +127,29 @@ pivot_data <- function(
#' umberto10_data_pivot_list <- kwb.umberto::create_pivot_list(umberto10_data_pivot)
#' head(umberto10_data_pivot_list)
#'
create_pivot_list <- function(pivot_data, arrange_cols = "process")
create_pivot_list <- function(
pivot_data,
arrange_cols = "process",
method_col = "lci_method"
)
{
myList <- list()

lci_methods <- unique(pivot_data$lci_method)
method_vector <- kwb.utils::selectColumns(pivot_data, method_col)

lci_methods <- unique(method_vector)

for (i in seq_along(lci_methods)) {

selected_lci_method <- unique(pivot_data$lci_method)[i]
selected_lci_method <- lci_methods[i]

processes <- data.frame(
lci_method = selected_lci_method,
process = unique(pivot_data$process),
process = unique(kwb.utils::selectColumns(pivot_data, "process")),
stringsAsFactors = FALSE
)

tmp_data <- pivot_data[pivot_data$lci_method == selected_lci_method,] %>%
tmp_data <- pivot_data[method_vector == selected_lci_method, ] %>%
dplyr::right_join(processes) %>%
dplyr::arrange_(arrange_cols)

Expand Down

0 comments on commit fb57971

Please sign in to comment.