diff --git a/NEWS.md b/NEWS.md index bd0f27645..f81712597 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 diff --git a/R/wb_functions.R b/R/wb_functions.R index 1748c6a24..bcce86d84 100644 --- a/R/wb_functions.R +++ b/R/wb_functions.R @@ -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 diff --git a/tests/testthat/test-wb_functions.R b/tests/testthat/test-wb_functions.R index 8481126a8..28317f449 100644 --- a/tests/testthat/test-wb_functions.R +++ b/tests/testthat/test-wb_functions.R @@ -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(