diff --git a/R/read.R b/R/read.R index 7717c07fa..84d1d95e2 100644 --- a/R/read.R +++ b/R/read.R @@ -309,7 +309,7 @@ wb_to_df <- function( keep_rows <- keep_rows[keep_rows %in% rnams] # reduce data to selected cases only - if (!is.null(cols) && !is.null(rows) && !missing(dims)) + if (length(keep_rows) && length(keep_cols)) cc <- cc[cc$row_r %in% keep_rows & cc$c_r %in% keep_cols, ] cc$val <- NA_character_ diff --git a/tests/testthat/test-wb_functions.R b/tests/testthat/test-wb_functions.R index d717e03a3..c4352d96f 100644 --- a/tests/testthat/test-wb_functions.R +++ b/tests/testthat/test-wb_functions.R @@ -304,3 +304,14 @@ test_that("cols return order is correct", { expect_equal(exp, got) }) + +test_that("missings cells are returned", { + + wb <- wb_workbook()$add_worksheet()$add_data(x = "a", dims = "Z100") + + expect_silent(got <- wb_to_df(wb, col_names = FALSE, rows = 1, cols = 1)) + expect_silent(got <- wb_to_df(wb, col_names = FALSE, rows = c(1, 4, 10), cols = c(2, 5, 10))) + + expect_silent(got <- wb_to_df(wb, col_names = FALSE, rows = c(101), cols = c(27))) + +})