Skip to content

Commit

Permalink
[wb_dims] move code up so that frow creation is in a single condition
Browse files Browse the repository at this point in the history
  • Loading branch information
JanMarvin committed Jul 30, 2024
1 parent 70e78e7 commit d60802a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
13 changes: 8 additions & 5 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,14 @@ wb_dims <- function(..., select = NULL) {
fcol <- fcol + row_names
frow <- frow + col_names
}

# for cases were cols and rows are vectors and row 1 is selected
# frow is a scalar and rows_arg is a vector. We need the vector.
# it's mystery, why crossing 1 is such an issue.
if (is.null(args$x) && !all(diff(rows_arg) == 1L)) {
diff <- min(frow) - min(rows_arg)
frow <- diff + rows_arg
}
}

# Ensure we are spanning at least 1 row and 1 col
Expand All @@ -934,11 +942,6 @@ wb_dims <- function(..., select = NULL) {
ncol_to_span <- 1L
}

if (is.null(args$x) && !all(diff(rows_arg) == 1L)) {
diff <- min(frow) - min(rows_arg)
frow <- diff + rows_arg
}

if (all(diff(frow) == 1))
row_span <- frow + seq_len(nrow_to_span) - 1L
else
Expand Down
4 changes: 4 additions & 0 deletions tests/testthat/test-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,10 @@ test_that("wb_dims() corner cases work", {
got <- wb_dims(rows = c(1, 30), cols = 2) # expect B1,B30
expect_equal(exp, got)

exp <- "B11:B11,B40:B40"
got <- wb_dims(rows = c(1, 30), cols = 2, from_row = 11)
expect_equal(exp, got)

exp <- "B2:B2,D2:D2,B30:B30,D30:D30"
got <- wb_dims(rows = c(2, 30), cols = c(2, 4)) # expect B2,D2,B30,D30
expect_equal(exp, got)
Expand Down

0 comments on commit d60802a

Please sign in to comment.