Skip to content

Commit

Permalink
[wb_to_df] make equal sized non consecutive dims behave similar to un…
Browse files Browse the repository at this point in the history
…equal sized non concsecutive dims. (#1183)

`dims = "A1:A5,C1:D5"` behaves similar to `dims = "A1,C1:D1,A2:A5,C2:D5"`
  • Loading branch information
JanMarvin authored Nov 15, 2024
1 parent f8943ca commit 1e3df93
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## New features

* `wb_set_properties()` now has a `datetime_modify` option. [1176](https://github.com/JanMarvin/openxlsx2/pull/1176)
* Make non consecutive equal sized dims behave similar to non equal sized non consecutive dims. This makes `dims = "A1:A5,C1:D5"` behave similar to `dims = "A1,C1:D1,A2:A5,C2:D5"`.

## Fixes

Expand Down
1 change: 1 addition & 0 deletions R/wb_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ dims_to_dataframe <- function(dims, fill = FALSE, empty_rm = FALSE) {
full_cols <- sort(get_dims(dims, cols = TRUE))

rows_out <- unlist(full_rows)
rows_out <- seq.int(rows_out[1], rows_out[2])
cols_out <- int2col(full_cols)
full_cols <- full_cols - min(full_cols) # is always a zero offset

Expand Down
15 changes: 15 additions & 0 deletions tests/testthat/test-wb_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,21 @@ test_that("improve non consecutive dims", {
expect_contains(got, exp)
})

test_that("reading equal sized ranges works", {

df <- as.data.frame(matrix(rep(1:4, 4), 4, 4, byrow = TRUE))

wb <- wb_workbook()$add_worksheet()$add_data(x = df)

exp <- df[, -2]
got <- wb_to_df(wb, dims = "A1:A5,C1:D5")
expect_equal(exp, got, ignore_attr = TRUE)

got <- wb_to_df(wb, dims = "A1,C1:D1,A2:A5,C2:D5")
expect_equal(exp, got, ignore_attr = TRUE)

})

test_that("creating a formula matrix works", {

df <- matrix(
Expand Down

0 comments on commit 1e3df93

Please sign in to comment.