Skip to content

Commit

Permalink
[wb_dims] extend tests and minor code indentations
Browse files Browse the repository at this point in the history
  • Loading branch information
JanMarvin committed Aug 16, 2024
1 parent a23b550 commit a170a21
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
8 changes: 4 additions & 4 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ wb_dims <- function(..., select = NULL) {
frow <- args$from_row %||% 1L
}

left <- args$left
left <- args$left
right <- args$right
above <- args$above
below <- args$below
Expand All @@ -744,10 +744,10 @@ wb_dims <- function(..., select = NULL) {
# NCOL(NULL)/NROW(NULL) could work as well, but the behavior might have
# changed recently.
if (!is.null(args$x)) {
width_x <- ncol(args$x) + rnms
height_x <- nrow(args$x) + cnms
width_x <- NCOL(args$x) + rnms
height_x <- NROW(args$x) + cnms
} else {
width_x <- 1
width_x <- 1
height_x <- 1
}

Expand Down
36 changes: 34 additions & 2 deletions tests/testthat/test-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,46 @@ test_that("wb_dims() works when not supplying `x`.", {

test_that("wb_dims() works with above and one line", {
expect_equal(wb_dims(x = names(mtcars), from_row = 2), "A2:A12")

# doesn't work
# expect_equal(wb_dims(x = names(mtcars), from_row = 3, above = 1), "A2:A12")
expect_equal(wb_dims(x = names(mtcars), from_row = 2, above = 1), "A1:A11")
expect_equal(wb_dims(x = names(mtcars), from_dims = "A2", above = 1), "A1:A11")

expect_warning(
expect_equal(
wb_dims(x = names(mtcars), from_row = 2, above = 1),
"A1:A11"
),
"rows cannot be above of row 1 "
)

expect_warning(
expect_equal(
wb_dims(x = names(mtcars), from_dims = "A2", above = 1),
"A1:A11"),
"rows cannot be above of row 1 "
)

# Doesn't work returns A1:A11
# expect_equal(wb_dims(x = names(mtcars), from_dims = "A3", above = 1), "A2:A12")
# Doesn't work returns A1:A11
# expect_equal(wb_dims(x = names(mtcars), from_dims = "A4", above = 1), "A3:A13")

# currently the only ways to create horizontal single row dims with wb_dims()

nms <- mtcars[NULL, ]

expect_equal(wb_dims(x = nms, from_row = 3), "A3:K3")
expect_equal(wb_dims(x = nms, from_row = 3, above = 1), "A2:K2")
expect_equal(wb_dims(x = nms, from_dims = "A3"), "A3:K3")
expect_equal(wb_dims(x = nms, from_dims = "A3", above = 1), "A2:K2")
expect_equal(wb_dims(x = nms, from_dims = "A4", above = 1), "A3:K3")

expect_equal(wb_dims(x = t(names(mtcars)), col_names = FALSE, from_row = 3), "A3:K3")
expect_equal(wb_dims(x = t(names(mtcars)), col_names = FALSE, from_row = 3, above = 1), "A2:K2")
expect_equal(wb_dims(x = t(names(mtcars)), col_names = FALSE, from_dims = "A3"), "A3:K3")
expect_equal(wb_dims(x = t(names(mtcars)), col_names = FALSE, from_dims = "A3", above = 1), "A2:K2")
expect_equal(wb_dims(x = t(names(mtcars)), col_names = FALSE, from_dims = "A4", above = 1), "A3:K3")

})

test_that("`wb_dims()` can select content in a nice fashion with `x`", {
Expand Down

0 comments on commit a170a21

Please sign in to comment.