Skip to content

Commit

Permalink
[misc] restore start_row/start_col in deprecated function arguments. C…
Browse files Browse the repository at this point in the history
…loses #952 (#953)

* begin new development

* [misc] fix start_row/start_col arguments
  • Loading branch information
JanMarvin committed Feb 20, 2024
1 parent ee3590b commit da06c08
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 14 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: openxlsx2
Title: Read, Write and Edit 'xlsx' Files
Version: 1.4
Version: 1.4.0.9000
Language: en-US
Authors@R: c(
person("Jordan Mark", "Barbone", email = "jmbarbone@gmail.com", role = "aut", comment = c(ORCID = "0000-0001-9788-3628")),
Expand Down
8 changes: 7 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# openxlsx2 (in development)


***************************************************************************


# openxlsx2 1.4

## New features
Expand Down Expand Up @@ -29,7 +35,7 @@
* Updating to themes. This includes updates to the default style `'Office Theme'` [899](https://github.com/JanMarvin/openxlsx2/pull/899)
* This includes switching to the new default font `'Aptos Narrow'`
* A new style `'Office 2013 - 2022 Theme'` was added

Users that want to remain on the old style should use `wb_workbook(theme = 'Office 2013 - 2022 Theme')` or `wb_set_base_font(font_name = "Calibri")`.

## Maintenance
Expand Down
34 changes: 22 additions & 12 deletions R/class-workbook.R
Original file line number Diff line number Diff line change
Expand Up @@ -4912,13 +4912,17 @@ wbWorkbook <- R6::R6Class(
arguments <- c(ls(), "start_row", "start_col")
standardize_case_names(..., arguments = arguments)

if ((exists("start_row") && !is.null(start_row)) ||
(exists("start_col") && !is.null(start_col))) {
if (!exists("start_row") || is.null(start_row)) start_row <- 1
if (!exists("start_row") || is.null(start_col)) start_col <- 1
params <- list(...)
if (!is.null(params$start_row)) start_row <- params$start_row
if (!is.null(params$start_col)) start_col <- params$start_col

if (exists("start_row") || exists("start_col")) {
if (!exists("start_row")) start_row <- 1
if (!exists("start_col")) start_col <- 1
.Deprecated(old = "start_col/start_row", new = "dims", package = "openxlsx2")
start_col <- col2int(start_col)
start_row <- as.integer(start_row)
dims <- rowcol_to_dim(start_row, start_col)
}

if (!file.exists(file)) {
Expand Down Expand Up @@ -5044,10 +5048,13 @@ wbWorkbook <- R6::R6Class(
arguments <- c(ls(), "start_row", "start_col")
standardize_case_names(..., arguments = arguments)

if ((exists("start_row") && !is.null(start_row)) ||
(exists("start_col") && !is.null(start_col))) {
if (!exists("start_row") || is.null(start_row)) start_row <- 1
if (!exists("start_row") || is.null(start_col)) start_col <- 1
params <- list(...)
if (!is.null(params$start_row)) start_row <- params$start_row
if (!is.null(params$start_col)) start_col <- params$start_col

if (exists("start_row") || exists("start_col")) {
if (!exists("start_row")) start_row <- 1
if (!exists("start_col")) start_col <- 1
.Deprecated(old = "start_row/start_col", new = "dims", package = "openxlsx2")
dims <- rowcol_to_dim(start_row, start_col)
}
Expand Down Expand Up @@ -5300,10 +5307,13 @@ wbWorkbook <- R6::R6Class(
arguments <- c(ls(), "start_row", "start_col")
standardize_case_names(..., arguments = arguments)

if ((exists("start_row") && !is.null(start_row)) ||
(exists("start_col") && !is.null(start_col))) {
if (!exists("start_row") || is.null(start_row)) start_row <- 1
if (!exists("start_row") || is.null(start_col)) start_col <- 1
params <- list(...)
if (!is.null(params$start_row)) start_row <- params$start_row
if (!is.null(params$start_col)) start_col <- params$start_col

if (exists("start_row") || exists("start_col")) {
if (!exists("start_row")) start_row <- 1
if (!exists("start_col")) start_col <- 1
.Deprecated(old = "start_col/start_row", new = "dims", package = "openxlsx2")
dims <- rowcol_to_dim(start_row, start_col)
}
Expand Down
47 changes: 47 additions & 0 deletions tests/testthat/test-class-workbook.R
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,53 @@ test_that("image relships work with comment", {

})

test_that("start_col/start_row works as expected", {
img <- system.file("extdata", "einstein.jpg", package = "openxlsx2")
expect_warning(wb <- wb_workbook()$add_worksheet()$add_image(file = img, start_row = 5), "'start_col/start_row' is deprecated.")

exp <- "<xdr:from><xdr:col>0</xdr:col><xdr:colOff>0</xdr:colOff><xdr:row>4</xdr:row><xdr:rowOff>0</xdr:rowOff></xdr:from>"
got <- xml_node(wb$drawings[[1]], "xdr:wsDr", "xdr:oneCellAnchor", "xdr:from")
expect_equal(exp, got)

img <- system.file("extdata", "einstein.jpg", package = "openxlsx2")
expect_warning(wb <- wb_workbook()$add_worksheet()$add_image(file = img, startRow = 5), "'start_col/start_row' is deprecated.")

exp <- "<xdr:from><xdr:col>0</xdr:col><xdr:colOff>0</xdr:colOff><xdr:row>4</xdr:row><xdr:rowOff>0</xdr:rowOff></xdr:from>"
got <- xml_node(wb$drawings[[1]], "xdr:wsDr", "xdr:oneCellAnchor", "xdr:from")
expect_equal(exp, got)


img <- system.file("extdata", "einstein.jpg", package = "openxlsx2")
expect_warning(wb <- wb_workbook()$add_worksheet()$add_image(file = img, start_col = 5), "'start_col/start_row' is deprecated.")

exp <- "<xdr:from><xdr:col>4</xdr:col><xdr:colOff>0</xdr:colOff><xdr:row>0</xdr:row><xdr:rowOff>0</xdr:rowOff></xdr:from>"
got <- xml_node(wb$drawings[[1]], "xdr:wsDr", "xdr:oneCellAnchor", "xdr:from")
expect_equal(exp, got)

img <- system.file("extdata", "einstein.jpg", package = "openxlsx2")
expect_warning(wb <- wb_workbook()$add_worksheet()$add_image(file = img, startCol = 5), "'start_col/start_row' is deprecated.")

exp <- "<xdr:from><xdr:col>4</xdr:col><xdr:colOff>0</xdr:colOff><xdr:row>0</xdr:row><xdr:rowOff>0</xdr:rowOff></xdr:from>"
got <- xml_node(wb$drawings[[1]], "xdr:wsDr", "xdr:oneCellAnchor", "xdr:from")
expect_equal(exp, got)


img <- system.file("extdata", "einstein.jpg", package = "openxlsx2")
expect_warning(wb <- wb_workbook()$add_worksheet()$add_image(file = img, start_col = 5, start_row = 5), "'start_col/start_row' is deprecated.")

exp <- "<xdr:from><xdr:col>4</xdr:col><xdr:colOff>0</xdr:colOff><xdr:row>4</xdr:row><xdr:rowOff>0</xdr:rowOff></xdr:from>"
got <- xml_node(wb$drawings[[1]], "xdr:wsDr", "xdr:oneCellAnchor", "xdr:from")
expect_equal(exp, got)


img <- system.file("extdata", "einstein.jpg", package = "openxlsx2")
expect_warning(wb <- wb_workbook()$add_worksheet()$add_image(file = img, startCol = 5, startRow = 5), "'start_col/start_row' is deprecated.")

exp <- "<xdr:from><xdr:col>4</xdr:col><xdr:colOff>0</xdr:colOff><xdr:row>4</xdr:row><xdr:rowOff>0</xdr:rowOff></xdr:from>"
got <- xml_node(wb$drawings[[1]], "xdr:wsDr", "xdr:oneCellAnchor", "xdr:from")
expect_equal(exp, got)
})

test_that("workbook themes work", {

wb <- wb_workbook()$add_worksheet()
Expand Down

0 comments on commit da06c08

Please sign in to comment.