Skip to content

Commit 48e3898

Browse files
committed
[read] avoid breaking with zero rows in cc
1 parent ffa95fd commit 48e3898

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

R/read.R

+19-5
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,13 @@ wb_to_df <- function(
341341
if (has_dims && length(keep_rows) && length(keep_cols))
342342
cc <- cc[cc$row_r %in% keep_rows & cc$c_r %in% keep_cols, ]
343343

344-
cc$val <- NA_character_
345-
cc$typ <- NA_character_
344+
if (nrow(cc) == 0) {
345+
cc$val <- character()
346+
cc$typ <- character()
347+
} else {
348+
cc$val <- NA_character_
349+
cc$typ <- NA_character_
350+
}
346351

347352
cc_tab <- unique(cc$c_t)
348353

@@ -402,7 +407,11 @@ wb_to_df <- function(
402407

403408
# if a cell is t="s" the content is a sst and not da date
404409
if (detect_dates && missing(types)) {
405-
cc$is_string <- FALSE
410+
if (nrow(cc) == 0) {
411+
cc$is_string <- logical()
412+
} else {
413+
cc$is_string <- FALSE
414+
}
406415
if (!is.null(cc$c_t))
407416
cc$is_string <- cc$c_t %in% c("s", "str", "b", "inlineStr")
408417

@@ -481,8 +490,13 @@ wb_to_df <- function(
481490

482491
# prepare to create output object z
483492
zz <- cc[c("val", "typ")]
484-
zz$cols <- NA_integer_
485-
zz$rows <- NA_integer_
493+
if (nrow(zz) == 0) {
494+
zz$cols <- integer()
495+
zz$rows <- integer()
496+
} else {
497+
zz$cols <- NA_integer_
498+
zz$rows <- NA_integer_
499+
}
486500
# we need to create the correct col and row position as integer starting at 0. Because we allow
487501
# to select specific rows and columns, we must make sure that our zz cols and rows matches the
488502
# z data frame.

0 commit comments

Comments
 (0)