diff --git a/R/class-workbook.R b/R/class-workbook.R index 2029fc028..47c8e649e 100644 --- a/R/class-workbook.R +++ b/R/class-workbook.R @@ -1383,6 +1383,12 @@ wbWorkbook <- R6::R6Class( if (missing(pivot_table)) pivot_table <- NULL if (missing(params)) params <- NULL + if_not_missing <- function(x) if (missing(x)) "" else as.character(x) + + if (any(duplicated(c(if_not_missing(filter), if_not_missing(rows), if_not_missing(cols))))) { + stop("duplicated variable in filter, rows, and cols detected.") + } + if (!missing(fun) && !missing(data)) { if (length(fun) < length(data)) { fun <- rep(fun[1], length(data)) diff --git a/R/helper-functions.R b/R/helper-functions.R index d643a1357..7337588cb 100644 --- a/R/helper-functions.R +++ b/R/helper-functions.R @@ -827,8 +827,8 @@ create_pivot_table <- function( if (!abs(sort) %in% seq_along(rows_pos)) warning("invalid sort position found") - if (!abs(sort) == match(i, rows_pos)) - sort <- NULL + if (!abs(sort) == match(i, rows_pos)) + sort <- NULL } } @@ -840,8 +840,8 @@ create_pivot_table <- function( if (!abs(sort) %in% seq_along(cols_pos)) warning("invalid sort position found") - if (!abs(sort) == match(i, cols_pos)) - sort <- NULL + if (!abs(sort) == match(i, cols_pos)) + sort <- NULL } } @@ -864,8 +864,12 @@ create_pivot_table <- function( else sort <- "ascending" } + sort_item <- params$sort_item + choose <- params$choose + multi <- if (is.null(choose)) NULL else as_xml_attr(TRUE) + attrs <- c( - axis, dataField, showAll = "0", sortType = sort, + axis, dataField, showAll = "0", multipleItemSelectionAllowed = multi, sortType = sort, compact = as_xml_attr(compact), outline = as_xml_attr(outline) ) @@ -873,9 +877,6 @@ create_pivot_table <- function( "pivotField", xml_attributes = attrs) - sort_item <- params$sort_item - choose <- params$choose - if (i %in% c(filter_pos, rows_pos, cols_pos)) { nms <- names(x[i]) sort_itm <- sort_item[[nms]]