diff --git a/R/writeData.R b/R/writeData.R index fef00f78..9ca2593d 100644 --- a/R/writeData.R +++ b/R/writeData.R @@ -14,7 +14,7 @@ #' \code{c(startCol, startRow)}. #' @param colNames If \code{TRUE}, column names of x are written. #' @param rowNames If \code{TRUE}, data.frame row names of x are written. -#' @param row.names Deprecated, please use \code{rowNames} instead +#' @param row.names,col.names Deprecated, please use \code{rowNames}, \code{colNames} instead #' @param headerStyle Custom style to apply to column names. #' @param borders Either "\code{none}" (default), "\code{surrounding}", #' "\code{columns}", "\code{rows}" or \emph{respective abbreviations}. If @@ -175,6 +175,7 @@ writeData <- function( na.string = openxlsx_getOp("na.string"), name = NULL, sep = ", ", + col.names, row.names ) { @@ -186,6 +187,11 @@ writeData <- function( rowNames <- row.names } + if (!missing(col.names)) { + warning("Please use 'colNames' instead of 'col.names'", call. = FALSE) + colNames <- col.names + } + # Set NULLs borders <- borders %||% "none" borderColour <- borderColour %||% "black" diff --git a/R/writeDataTable.R b/R/writeDataTable.R index 0c54a5df..011759e7 100644 --- a/R/writeDataTable.R +++ b/R/writeDataTable.R @@ -12,7 +12,7 @@ #' A vector of the form c(startCol, startRow) #' @param colNames If \code{TRUE}, column names of x are written. #' @param rowNames If \code{TRUE}, row names of x are written. -#' @param row.names Deprecated, please use \code{rowNames} instead +#' @param row.names,col.names Deprecated, please use \code{rowNames}, \code{colNames} instead #' @param tableStyle Any excel table style name or "none" (see "formatting" vignette). #' @param tableName name of table in workbook. The table name must be unique. #' @param headerStyle Custom style to apply to column names. @@ -157,6 +157,7 @@ writeDataTable <- function( lastColumn = openxlsx_getOp("lastColumn", FALSE), bandedRows = openxlsx_getOp("bandedRows", TRUE), bandedCols = openxlsx_getOp("bandedCols", FALSE), + col.names, row.names ) { op <- get_set_options() @@ -169,6 +170,11 @@ writeDataTable <- function( row.names <- rowNames } + if (!missing(col.names)) { + warning("Please use 'colNames' instead of 'col.names'", call. = FALSE) + colNames <- col.names + } + # Set NULLs withFilter <- withFilter %||% TRUE keepNA <- keepNA %||% FALSE diff --git a/man/writeData.Rd b/man/writeData.Rd index 49018d63..43247095 100644 --- a/man/writeData.Rd +++ b/man/writeData.Rd @@ -23,6 +23,7 @@ writeData( na.string = openxlsx_getOp("na.string"), name = NULL, sep = ", ", + col.names, row.names ) } @@ -86,7 +87,7 @@ each column. If "\code{all}" all cell borders are drawn.} \item{sep}{Only applies to list columns. The separator used to collapse list columns to a character vector e.g. sapply(x$list_column, paste, collapse = sep).} -\item{row.names}{Deprecated, please use \code{rowNames} instead} +\item{row.names, col.names}{Deprecated, please use \code{rowNames}, \code{colNames} instead} } \value{ invisible(0) diff --git a/man/writeDataTable.Rd b/man/writeDataTable.Rd index de55ee08..b7bdeaba 100644 --- a/man/writeDataTable.Rd +++ b/man/writeDataTable.Rd @@ -25,6 +25,7 @@ writeDataTable( lastColumn = openxlsx_getOp("lastColumn", FALSE), bandedRows = openxlsx_getOp("bandedRows", TRUE), bandedCols = openxlsx_getOp("bandedCols", FALSE), + col.names, row.names ) } @@ -77,7 +78,7 @@ existing style is replaced by the new style. \item{bandedCols}{logical. If TRUE, the columns are colour banded} -\item{row.names}{Deprecated, please use \code{rowNames} instead} +\item{row.names, col.names}{Deprecated, please use \code{rowNames}, \code{colNames} instead} } \description{ Write to a worksheet and format as an Excel table diff --git a/tests/testthat/test-build_workbook.R b/tests/testthat/test-build_workbook.R index 4d144bad..aee84e21 100644 --- a/tests/testthat/test-build_workbook.R +++ b/tests/testthat/test-build_workbook.R @@ -16,3 +16,27 @@ test_that("buildWorkbook() accepts tableName [187]", { # try to define 1/2 table names expect_error(buildWorkbook(list(x, x), asTable = TRUE, tableName = "table_x")) }) + +test_that("row.name and col.name are deprecated", { + x <- data.frame(a = 1) + + expect_warning( + buildWorkbook(x, file = temp_xlsx(), row.names = TRUE, overwrite = TRUE), + "Please use 'rowNames' instead of 'row.names'" + ) + + expect_warning( + buildWorkbook(x, file = temp_xlsx(), row.names = TRUE, overwrite = TRUE, asTable = TRUE), + "Please use 'rowNames' instead of 'row.names'" + ) + + expect_warning( + buildWorkbook(x, file = temp_xlsx(), col.names = TRUE, overwrite = TRUE), + "Please use 'colNames' instead of 'col.names'" + ) + + expect_warning( + buildWorkbook(x, file = temp_xlsx(), col.names = TRUE, overwrite = TRUE, asTable = TRUE), + "Please use 'colNames' instead of 'col.names'" + ) +}) diff --git a/tests/testthat/test-write_read_equality.R b/tests/testthat/test-write_read_equality.R index f686ff93..136c4cc9 100644 --- a/tests/testthat/test-write_read_equality.R +++ b/tests/testthat/test-write_read_equality.R @@ -119,11 +119,6 @@ test_that("Writing then reading rowNames, colNames combinations", { curr_wd <- getwd() mt <- utils::head(mtcars) # don't need the whole thing - expect_warning( - write.xlsx(mt, file = temp_xlsx(), row.names = TRUE, overwrite = TRUE), - "Please use 'rowNames' instead of 'row.names'" - ) - # write the row and column names for testing write.xlsx(mt, file = fileName, overwrite = TRUE, rowNames = TRUE, colNames = TRUE)