Skip to content

Commit

Permalink
change default for wb_dims()
Browse files Browse the repository at this point in the history
  • Loading branch information
JanMarvin committed Jul 15, 2023
1 parent 21967f1 commit 3574547
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
23 changes: 13 additions & 10 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -276,17 +276,11 @@ wb_dims <- function(...) {
col_names <- args$col_names
row_names <- args$row_names

has_cnam <- is.null(col_names)
has_rnam <- is.null(row_names)

if (has_cnam) col_names <- FALSE
if (has_rnam) row_names <- FALSE

assert_class(col_names, "logical")
assert_class(row_names, "logical")
cnam_null <- is.null(col_names)
rnam_null <- is.null(row_names)

# wb_dims(rows, cols)
if (length(args) == 2 && has_cnam && has_rnam) {
if (length(args) == 2 && cnam_null && rnam_null) {
rows <- 1L
cols <- 2L

Expand All @@ -305,8 +299,17 @@ wb_dims <- function(...) {

} else {

x <- args[[1]]
exp_name <- inherits(x, "data.frame") || inherits(x, "matrix")

if (cnam_null) col_names <- exp_name
if (rnam_null) row_names <- FALSE

assert_class(col_names, "logical")
assert_class(row_names, "logical")

# wb_dims(data.frame())
x <- as.data.frame(args[[1]])
x <- as.data.frame(x)
rows <- seq_len(nrow(x) + col_names)
cols <- seq_len(ncol(x) + row_names)

Expand Down
8 changes: 3 additions & 5 deletions tests/testthat/test-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,12 @@ test_that("dims to col & row and back", {

test_that("wb_dims() works", {

# dim(mtcars)

expect_equal(wb_dims(mtcars), "A1:K32")
expect_equal(wb_dims(mtcars, col_names = TRUE, row_names = TRUE), "A1:L33")
expect_equal(wb_dims(mtcars), "A1:K33")
expect_equal(wb_dims(mtcars, col_names = FALSE, row_names = TRUE), "A1:L32")

expect_equal(wb_dims(letters), "A1:A26")

expect_equal(wb_dims(t(letters)), "A1:Z1")
expect_equal(wb_dims(t(letters)), "A1:Z2")

expect_equal(wb_dims(1), "A1")

Expand Down

0 comments on commit 3574547

Please sign in to comment.