diff --git a/R/class-comment.R b/R/class-comment.R index fda4955d4..d2cecb91f 100644 --- a/R/class-comment.R +++ b/R/class-comment.R @@ -213,8 +213,8 @@ do_write_comment <- function( if (!is.null(dims)) { ref <- dims - col <- col2int(dims_to_rowcol(dims)[[1]]) - row <- as.integer(dims_to_rowcol(dims)[[2]]) + col <- col2int(dims_to_rowcol(dims)[["col"]]) + row <- as.integer(dims_to_rowcol(dims)[["row"]]) } else { if (!is.numeric(col)) { col <- col2int(col) diff --git a/R/class-workbook.R b/R/class-workbook.R index 0bd7a5e80..12353a06f 100644 --- a/R/class-workbook.R +++ b/R/class-workbook.R @@ -1766,8 +1766,8 @@ wbWorkbook <- R6::R6Class( ddims <- dims_to_rowcol(dims, as_integer = TRUE) dims <- rowcol_to_dims( - row = c(ddims[[2]], ddims[[2]] + 12L), - col = c(ddims[[1]], ddims[[1]] + 1L) + row = c(ddims[["row"]], ddims[["row"]] + 12L), + col = c(ddims[["col"]], ddims[["col"]] + 1L) ) } @@ -2117,8 +2117,8 @@ wbWorkbook <- R6::R6Class( ddims <- dims_to_rowcol(dims, as_integer = TRUE) dims <- rowcol_to_dims( - row = c(ddims[[2]], ddims[[2]] + 12L), - col = c(ddims[[1]], ddims[[1]] + 1L) + row = c(ddims[["row"]], ddims[["row"]] + 12L), + col = c(ddims[["col"]], ddims[["col"]] + 1L) ) } @@ -3810,8 +3810,8 @@ wbWorkbook <- R6::R6Class( } rowcol <- dims_to_rowcol(ref) - ref_rows <- as.integer(rowcol[[2]]) - ref <- rowcol_to_dims(c(ref_rows, max(ref_rows) + 1L), rowcol[[1]]) + ref_rows <- as.integer(rowcol[["row"]]) + ref <- rowcol_to_dims(c(ref_rows, max(ref_rows) + 1L), rowcol[["col"]]) } @@ -5336,8 +5336,8 @@ wbWorkbook <- R6::R6Class( ddims <- dims_to_rowcol(dims) - rows <- ddims[[2]] - cols <- ddims[[1]] + rows <- ddims[["row"]] + cols <- ddims[["col"]] sheet <- private$get_sheet_index(sheet) self$worksheets[[sheet]]$unmerge_cells( @@ -5776,8 +5776,8 @@ wbWorkbook <- R6::R6Class( } ddims <- dims_to_rowcol(dims, as_integer = TRUE) - rows <- ddims[[2]] - cols <- ddims[[1]] + rows <- ddims[["row"]] + cols <- ddims[["col"]] if (!is.null(style)) assert_class(style, "character") assert_class(type, "character") @@ -5793,8 +5793,8 @@ wbWorkbook <- R6::R6Class( rows <- as.integer(rows) } else if (!is.null(dims)) { rowcol <- dims_to_rowcol(dims, as_integer = TRUE) - rows <- rowcol[[2]] - cols <- rowcol[[1]] + rows <- rowcol[["row"]] + cols <- rowcol[["col"]] } ## check valid rule @@ -6657,18 +6657,18 @@ wbWorkbook <- R6::R6Class( if (!is.null(dims)) { xy <- dims_to_rowcol(dims) - left <- col2int(xy[[1]][1]) - 1L - top <- as.integer(xy[[2]][1]) - 1L + left <- col2int(xy[["col"]][1]) - 1L + top <- as.integer(xy[["row"]][1]) - 1L # for A1:B2 if (length(xy[[1]]) > 1) { - right <- max(col2int(xy[[1]])) + right <- max(col2int(xy[["col"]])) } else { right <- left + 1L } if (length(xy[[2]]) > 1) { - bottom <- max(as.integer(xy[[2]])) + bottom <- max(as.integer(xy[["row"]])) } else { bottom <- top + 1L } @@ -7937,8 +7937,8 @@ wbWorkbook <- R6::R6Class( } rowcols <- dims_to_rowcol(dims, as_integer = TRUE) - rows <- rowcols[[2]] - cols <- rowcols[[1]] + rows <- rowcols[["row"]] + cols <- rowcols[["col"]] startCol <- min(cols) endCol <- max(cols) @@ -8931,7 +8931,7 @@ wbWorkbook <- R6::R6Class( if (!is.null(rows)) { if (is.character(rows)) # row2int - rows <- as.integer(dims_to_rowcol(rows)[[2]]) + rows <- as.integer(dims_to_rowcol(rows)[["row"]]) dims <- wb_dims(rows, "A") cells <- unname(unlist(dims_to_dataframe(dims, fill = TRUE))) diff --git a/R/class-worksheet.R b/R/class-worksheet.R index cf53b5ad1..59259bef6 100644 --- a/R/class-worksheet.R +++ b/R/class-worksheet.R @@ -522,8 +522,8 @@ wbWorksheet <- R6::R6Class( ddims <- dims_to_rowcol(dims) - rows <- ddims[[2]] - cols <- ddims[[1]] + rows <- ddims[["row"]] + cols <- ddims[["col"]] rows <- range(as.integer(rows)) cols <- range(col2int(cols)) diff --git a/R/helper-functions.R b/R/helper-functions.R index a9a91eb9c..2ebb93bb0 100644 --- a/R/helper-functions.R +++ b/R/helper-functions.R @@ -1266,7 +1266,7 @@ fits_in_dims <- function(x, dims, startCol, startRow) { if (fits) { # why oh why wasn't dims_to_rowcol()/rowcol_to_dims() created as a matching pair - dims <- rowcol_to_dims(row = dims[[2]], col = dims[[1]]) + dims <- rowcol_to_dims(row = dims[["row"]], col = dims[["col"]]) } else { @@ -1288,7 +1288,7 @@ fits_in_dims <- function(x, dims, startCol, startRow) { } rc <- dims_to_rowcol(dims) - if (max(as.integer(rc[[2]])) > 1048576 || max(col2int(rc[[1]])) > 16384) + if (max(as.integer(rc[["row"]])) > 1048576 || max(col2int(rc[["col"]])) > 16384) stop("Dimensions exceed worksheet") dims diff --git a/R/utils.R b/R/utils.R index 53c172f97..c368b647a 100644 --- a/R/utils.R +++ b/R/utils.R @@ -167,7 +167,7 @@ random_string <- function(n = 1, length = 16, pattern = "[A-Za-z0-9]", keep_seed #' @param single argument indicating if [rowcol_to_dims()] returns a single cell dimension #' @returns #' * A `dims` string for `_to_dim` i.e "A1:A1" -#' * A list of rows and columns for `to_rowcol` +#' * A named list of rows and columns for `to_rowcol` #' @examples #' dims_to_rowcol("A1:J10") #' wb_dims(1:10, 1:10) @@ -223,7 +223,7 @@ dims_to_rowcol <- function(x, as_integer = FALSE) { rows_out <- unique(c(rows_out, rows)) } - list(cols_out, rows_out) + setNames(list(cols_out, rows_out), c("col", "row")) } #' @rdname dims_helper @@ -754,8 +754,8 @@ wb_dims <- function(..., select = NULL) { } # transform to from_row_and_col <- dims_to_rowcol(args$from_dims, as_integer = TRUE) - fcol <- from_row_and_col[[1]] - frow <- from_row_and_col[[2]] + fcol <- from_row_and_col[["col"]] + frow <- from_row_and_col[["row"]] } else { fcol <- args$from_col %||% 1L frow <- args$from_row %||% 1L diff --git a/R/write.R b/R/write.R index 51bff5d9d..226b45bc1 100644 --- a/R/write.R +++ b/R/write.R @@ -408,7 +408,7 @@ write_data2 <- function( rows_attr <- vector("list", nrow(rtyp)) # create - want_rows <- as.integer(dims_to_rowcol(dims)[[2]]) + want_rows <- as.integer(dims_to_rowcol(dims)[["row"]]) rows_attr <- empty_row_attr(n = length(want_rows)) # number of rows might differ if (enforce) rows_attr <- empty_row_attr(n = nrow(rtyp)) @@ -873,8 +873,8 @@ write_data_table <- function( if (!is.null(dims)) { dims <- dims_to_rowcol(dims, as_integer = TRUE) # if dims = "K1,A1" startCol = "A" and startRow = "1" are selected - startCol <- min(dims[[1]]) - startRow <- min(dims[[2]]) + startCol <- min(dims[["col"]]) + startRow <- min(dims[["row"]]) } # avoid stoi error with NULL @@ -1342,7 +1342,7 @@ do_write_formula <- function( # transpose match write_data_table if (array || enforce) { rc <- dims_to_rowcol(dims) - if (length(rc[[1]]) > length(rc[[2]])) { + if (length(rc[["col"]]) > length(rc[["row"]])) { dfx <- transpose_df(dfx) } } diff --git a/man/dims_helper.Rd b/man/dims_helper.Rd index bef91729e..46fddf6e9 100644 --- a/man/dims_helper.Rd +++ b/man/dims_helper.Rd @@ -24,7 +24,7 @@ rowcol_to_dims(row, col, single = TRUE) \value{ \itemize{ \item A \code{dims} string for \verb{_to_dim} i.e "A1:A1" -\item A list of rows and columns for \code{to_rowcol} +\item A named list of rows and columns for \code{to_rowcol} } } \description{ diff --git a/tests/testthat/test-utils.R b/tests/testthat/test-utils.R index 54cab1209..a13ccfeb3 100644 --- a/tests/testthat/test-utils.R +++ b/tests/testthat/test-utils.R @@ -15,19 +15,19 @@ test_that("rbindlist", { test_that("dims to col & row and back", { - exp <- list(c("A", "B"), c("1", "2")) + exp <- list(col = c("A", "B"), row = c("1", "2")) got <- dims_to_rowcol("A1:B2") expect_equal(exp, got) - exp <- list(1:2, 1:2) + exp <- list(col = 1:2, row = 1:2) got <- dims_to_rowcol("A1:B2", as_integer = TRUE) expect_equal(exp, got) - exp <- list(1:2, c(1L)) + exp <- list(col = 1:2, row = c(1L)) got <- dims_to_rowcol("A:B", as_integer = TRUE) expect_equal(exp, got) - exp <- list("A", c("1")) + exp <- list(col = "A", row = c("1")) got <- dims_to_rowcol("A:A", as_integer = FALSE) expect_equal(exp, got) diff --git a/tests/testthat/test-wb_functions.R b/tests/testthat/test-wb_functions.R index c0c485968..3cdcfb58c 100644 --- a/tests/testthat/test-wb_functions.R +++ b/tests/testthat/test-wb_functions.R @@ -186,7 +186,7 @@ test_that("dims_to_dataframe", { got <- dims_to_dataframe("A1;A2,C1;C2", fill = TRUE, empty_rm = TRUE) expect_equal(exp, got) - exp <- list(c("A", "B"), "1") + exp <- list(col = c("A", "B"), row = "1") got <- dims_to_rowcol("A1;B1") expect_equal(exp, got)