Skip to content

Commit da06c08

Browse files
authored
[misc] restore start_row/start_col in deprecated function arguments. Closes #952 (#953)
* begin new development * [misc] fix start_row/start_col arguments
1 parent ee3590b commit da06c08

File tree

4 files changed

+77
-14
lines changed

4 files changed

+77
-14
lines changed

DESCRIPTION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Type: Package
22
Package: openxlsx2
33
Title: Read, Write and Edit 'xlsx' Files
4-
Version: 1.4
4+
Version: 1.4.0.9000
55
Language: en-US
66
Authors@R: c(
77
person("Jordan Mark", "Barbone", email = "jmbarbone@gmail.com", role = "aut", comment = c(ORCID = "0000-0001-9788-3628")),

NEWS.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# openxlsx2 (in development)
2+
3+
4+
***************************************************************************
5+
6+
17
# openxlsx2 1.4
28

39
## New features
@@ -29,7 +35,7 @@
2935
* Updating to themes. This includes updates to the default style `'Office Theme'` [899](https://github.com/JanMarvin/openxlsx2/pull/899)
3036
* This includes switching to the new default font `'Aptos Narrow'`
3137
* A new style `'Office 2013 - 2022 Theme'` was added
32-
38+
3339
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")`.
3440

3541
## Maintenance

R/class-workbook.R

+22-12
Original file line numberDiff line numberDiff line change
@@ -4912,13 +4912,17 @@ wbWorkbook <- R6::R6Class(
49124912
arguments <- c(ls(), "start_row", "start_col")
49134913
standardize_case_names(..., arguments = arguments)
49144914

4915-
if ((exists("start_row") && !is.null(start_row)) ||
4916-
(exists("start_col") && !is.null(start_col))) {
4917-
if (!exists("start_row") || is.null(start_row)) start_row <- 1
4918-
if (!exists("start_row") || is.null(start_col)) start_col <- 1
4915+
params <- list(...)
4916+
if (!is.null(params$start_row)) start_row <- params$start_row
4917+
if (!is.null(params$start_col)) start_col <- params$start_col
4918+
4919+
if (exists("start_row") || exists("start_col")) {
4920+
if (!exists("start_row")) start_row <- 1
4921+
if (!exists("start_col")) start_col <- 1
49194922
.Deprecated(old = "start_col/start_row", new = "dims", package = "openxlsx2")
49204923
start_col <- col2int(start_col)
49214924
start_row <- as.integer(start_row)
4925+
dims <- rowcol_to_dim(start_row, start_col)
49224926
}
49234927

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

5047-
if ((exists("start_row") && !is.null(start_row)) ||
5048-
(exists("start_col") && !is.null(start_col))) {
5049-
if (!exists("start_row") || is.null(start_row)) start_row <- 1
5050-
if (!exists("start_row") || is.null(start_col)) start_col <- 1
5051+
params <- list(...)
5052+
if (!is.null(params$start_row)) start_row <- params$start_row
5053+
if (!is.null(params$start_col)) start_col <- params$start_col
5054+
5055+
if (exists("start_row") || exists("start_col")) {
5056+
if (!exists("start_row")) start_row <- 1
5057+
if (!exists("start_col")) start_col <- 1
50515058
.Deprecated(old = "start_row/start_col", new = "dims", package = "openxlsx2")
50525059
dims <- rowcol_to_dim(start_row, start_col)
50535060
}
@@ -5300,10 +5307,13 @@ wbWorkbook <- R6::R6Class(
53005307
arguments <- c(ls(), "start_row", "start_col")
53015308
standardize_case_names(..., arguments = arguments)
53025309

5303-
if ((exists("start_row") && !is.null(start_row)) ||
5304-
(exists("start_col") && !is.null(start_col))) {
5305-
if (!exists("start_row") || is.null(start_row)) start_row <- 1
5306-
if (!exists("start_row") || is.null(start_col)) start_col <- 1
5310+
params <- list(...)
5311+
if (!is.null(params$start_row)) start_row <- params$start_row
5312+
if (!is.null(params$start_col)) start_col <- params$start_col
5313+
5314+
if (exists("start_row") || exists("start_col")) {
5315+
if (!exists("start_row")) start_row <- 1
5316+
if (!exists("start_col")) start_col <- 1
53075317
.Deprecated(old = "start_col/start_row", new = "dims", package = "openxlsx2")
53085318
dims <- rowcol_to_dim(start_row, start_col)
53095319
}

tests/testthat/test-class-workbook.R

+47
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,53 @@ test_that("image relships work with comment", {
754754

755755
})
756756

757+
test_that("start_col/start_row works as expected", {
758+
img <- system.file("extdata", "einstein.jpg", package = "openxlsx2")
759+
expect_warning(wb <- wb_workbook()$add_worksheet()$add_image(file = img, start_row = 5), "'start_col/start_row' is deprecated.")
760+
761+
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>"
762+
got <- xml_node(wb$drawings[[1]], "xdr:wsDr", "xdr:oneCellAnchor", "xdr:from")
763+
expect_equal(exp, got)
764+
765+
img <- system.file("extdata", "einstein.jpg", package = "openxlsx2")
766+
expect_warning(wb <- wb_workbook()$add_worksheet()$add_image(file = img, startRow = 5), "'start_col/start_row' is deprecated.")
767+
768+
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>"
769+
got <- xml_node(wb$drawings[[1]], "xdr:wsDr", "xdr:oneCellAnchor", "xdr:from")
770+
expect_equal(exp, got)
771+
772+
773+
img <- system.file("extdata", "einstein.jpg", package = "openxlsx2")
774+
expect_warning(wb <- wb_workbook()$add_worksheet()$add_image(file = img, start_col = 5), "'start_col/start_row' is deprecated.")
775+
776+
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>"
777+
got <- xml_node(wb$drawings[[1]], "xdr:wsDr", "xdr:oneCellAnchor", "xdr:from")
778+
expect_equal(exp, got)
779+
780+
img <- system.file("extdata", "einstein.jpg", package = "openxlsx2")
781+
expect_warning(wb <- wb_workbook()$add_worksheet()$add_image(file = img, startCol = 5), "'start_col/start_row' is deprecated.")
782+
783+
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>"
784+
got <- xml_node(wb$drawings[[1]], "xdr:wsDr", "xdr:oneCellAnchor", "xdr:from")
785+
expect_equal(exp, got)
786+
787+
788+
img <- system.file("extdata", "einstein.jpg", package = "openxlsx2")
789+
expect_warning(wb <- wb_workbook()$add_worksheet()$add_image(file = img, start_col = 5, start_row = 5), "'start_col/start_row' is deprecated.")
790+
791+
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>"
792+
got <- xml_node(wb$drawings[[1]], "xdr:wsDr", "xdr:oneCellAnchor", "xdr:from")
793+
expect_equal(exp, got)
794+
795+
796+
img <- system.file("extdata", "einstein.jpg", package = "openxlsx2")
797+
expect_warning(wb <- wb_workbook()$add_worksheet()$add_image(file = img, startCol = 5, startRow = 5), "'start_col/start_row' is deprecated.")
798+
799+
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>"
800+
got <- xml_node(wb$drawings[[1]], "xdr:wsDr", "xdr:oneCellAnchor", "xdr:from")
801+
expect_equal(exp, got)
802+
})
803+
757804
test_that("workbook themes work", {
758805

759806
wb <- wb_workbook()$add_worksheet()

0 commit comments

Comments
 (0)