Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix index for hidden attribute when grouping columns #104

Merged
merged 1 commit into from
Oct 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
# openxlsx (development version)

## Bug Fixes

* Grouping columns after setting widths no longer throws an error ([#100](https://github.com/ycphs/openxlsx/issues/100))

# openxlsx 4.2.2

## New Features

* Added features for `conditionalFormatting` to support also 'contains not', 'begins with' and 'ends with'

* Added return value for `saveWorkbook()` the default value for `returnValue` is `FALSE` ([#71])(https://github.com/ycphs/openxlsx/issues/71)
* Added return value for `saveWorkbook()` the default value for `returnValue` is `FALSE` ([#71](https://github.com/ycphs/openxlsx/issues/71))

* Added Tests for new parameter of `saveWorkbook()`

## Bug Fixes

* Solved CRAN check errors based on the change disussed in (PR#17277)[https://bugs.r-project.org/bugzilla3/show_bug.cgi?id=17277]
* Solved CRAN check errors based on the change disussed in [PR#17277](https://bugs.r-project.org/bugzilla3/show_bug.cgi?id=17277)

# openxlsx 4.2.0

Expand Down
7 changes: 3 additions & 4 deletions R/wrappers.R
Original file line number Diff line number Diff line change
Expand Up @@ -4292,9 +4292,8 @@ groupColumns <- function(wb, sheet, cols, hidden = FALSE) {
}

levels <- rep("1", length(cols))

hidden <- rep(hidden, length.out = length(cols))

hidden <- hidden[!duplicated(cols)]
levels <- levels[!duplicated(cols)]
cols <- cols[!duplicated(cols)]
Expand All @@ -4307,8 +4306,8 @@ groupColumns <- function(wb, sheet, cols, hidden = FALSE) {
if (any(existing_cols %in% cols)) {
for (i in intersect(existing_cols, cols)) {
width_hidden <- attr(wb$colWidths[[sheet]], "hidden")[attr(wb$colWidths[[sheet]], "names") == i]
outline_hidden <- as.character(as.integer(hidden[i]))
outline_hidden <- as.character(as.integer(hidden))[cols == i]

if (width_hidden != outline_hidden) {
attr(wb$colWidths[[sheet]], "hidden")[attr(wb$colWidths[[sheet]], "names") == i] <- outline_hidden
}
Expand Down
19 changes: 19 additions & 0 deletions tests/testthat/test-outlines.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,22 @@ test_that("loading workbook preserves outlines", {
expect_equal(names(wb$outlineLevels[[1]]), c("3", "4"))
expect_equal(unique(attr(wb$outlineLevels[[1]], "hidden")[names(wb$outlineLevels[[1]]) %in% c("3", "4")]), "true")
})


test_that("Grouping after setting colwidths has correct length of hidden attributes", {
# Issue #100 - https://github.com/ycphs/openxlsx/issues/100

wb <- createWorkbook(title = "column width and grouping error")
addWorksheet(wb, sheetName = 1)

setColWidths(
wb,
sheet = 1,
cols = 1:100,
widths = 8
)

groupColumns(wb, sheet = 1, cols = 20:100, hidden = TRUE)

expect_equal(length(wb$colOutlineLevels[[1]]), length(attr(wb$colOutlineLevels[[1]], "hidden")))
})