Skip to content

Commit 74192d0

Browse files
authored
[misc] housekeeping deprecating (#1330)
* [misc] deprecate create_comment() * [misc] deprecate argument usage of rows/cols * [misc] prepare deprecation of camelCase conversion
1 parent c13b8ad commit 74192d0

30 files changed

+373
-417
lines changed

NEWS.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# openxlsx2 (development version)
22

3+
## Maintenance
4+
5+
* Legacy `create_comment()` is now deprecated in favor of `wb_comment()`.
6+
* Usage of `rows` and `cols` is now deprecated in favor of `wb_dims(rows = ..., cols = ...)`.
7+
38
## New features
49

510
* A normalization function was added for separators in formulas. In English locales, formulas require a comma as argument separator, locales that use the comma a decimal separator, a semicolon is used as argument separator. We added a check to replace semicolons added in formulas, because these were hard to spot and if overlooked could brick the XML worksheet.

R/class-comment.R

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -164,29 +164,6 @@ wb_comment <- function(
164164
invisible(wbComment$new(text = text, author = author, style = style, width = width, height = height, visible = visible))
165165
}
166166

167-
#' Create a comment
168-
#'
169-
#' Use [wb_comment()] in new code. See [openxlsx2-deprecated]
170-
#'
171-
#' @inheritParams wb_comment
172-
#' @param author A string, by default, will use "user"
173-
#' @param visible Default: `TRUE`. Is the comment visible by default?
174-
#' @keywords internal
175-
#' @returns a `wbComment` object
176-
#' @export
177-
create_comment <- function(text,
178-
author = Sys.info()[["user"]],
179-
style = NULL,
180-
visible = TRUE,
181-
width = 2,
182-
height = 4) {
183-
#
184-
if (getOption("openxlsx2.soon_deprecated", default = FALSE)) {
185-
.Deprecated("wb_comment()", old = "create_comment()")
186-
}
187-
wb_comment(text = text, author = author, style = style, visible = visible, width = width[1], height = height[1])
188-
}
189-
190167
do_write_comment <- function(
191168
wb,
192169
sheet,

R/class-workbook.R

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5321,13 +5321,7 @@ wbWorkbook <- R6::R6Class(
53215321
rows <- list(...)[["rows"]]
53225322

53235323
if (!is.null(rows) && !is.null(cols)) {
5324-
5325-
if (length(cols) > 2 && any(diff(cols) != 1))
5326-
warning("cols > 2, will create range from min to max.")
5327-
5328-
if (getOption("openxlsx2.soon_deprecated", default = FALSE))
5329-
.Deprecated(old = "cols/rows", new = "dims", package = "openxlsx2")
5330-
5324+
.Deprecated(old = "cols/rows", new = "dims", package = "openxlsx2")
53315325
dims <- rowcol_to_dims(rows, cols)
53325326
}
53335327

@@ -5345,13 +5339,7 @@ wbWorkbook <- R6::R6Class(
53455339
rows <- list(...)[["rows"]]
53465340

53475341
if (!is.null(rows) && !is.null(cols)) {
5348-
5349-
if (length(cols) > 2 && any(diff(cols) != 1))
5350-
warning("cols > 2, will create range from min to max.")
5351-
5352-
if (getOption("openxlsx2.soon_deprecated", default = FALSE))
5353-
.Deprecated(old = "cols/rows", new = "dims", package = "openxlsx2")
5354-
5342+
.Deprecated(old = "cols/rows", new = "dims", package = "openxlsx2")
53555343
dims <- rowcol_to_dims(rows, cols)
53565344
}
53575345

@@ -5796,20 +5784,17 @@ wbWorkbook <- R6::R6Class(
57965784
rows <- list(...)[["rows"]]
57975785

57985786
if (!is.null(rows) && !is.null(cols)) {
5799-
5800-
if (length(cols) > 2 && any(diff(cols) != 1))
5801-
warning("cols > 2, will create range from min to max.")
5802-
5803-
if (getOption("openxlsx2.soon_deprecated", default = FALSE))
5804-
.Deprecated(old = "cols/rows", new = "dims", package = "openxlsx2")
5805-
5787+
.Deprecated(old = "cols/rows", new = "dims", package = "openxlsx2")
58065788
dims <- rowcol_to_dims(rows, cols)
58075789
}
58085790

58095791
ddims <- dims_to_rowcol(dims, as_integer = TRUE)
58105792
rows <- ddims[["row"]]
58115793
cols <- ddims[["col"]]
58125794

5795+
if (length(cols) > 2 && any(diff(cols) != 1))
5796+
warning("cols > 2, will create range from min to max.")
5797+
58135798
if (!is.null(style)) assert_class(style, "character")
58145799
assert_class(type, "character")
58155800
assert_class(params, "list")

R/class-worksheet.R

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -523,10 +523,13 @@ wbWorksheet <- R6::R6Class(
523523
ddims <- dims_to_rowcol(dims)
524524

525525
rows <- ddims[["row"]]
526-
cols <- ddims[["col"]]
526+
cols <- col2int(ddims[["col"]])
527+
528+
if (length(cols) > 2 && any(diff(cols) != 1))
529+
warning("cols > 2, will create range from min to max.")
527530

528531
rows <- range(as.integer(rows))
529-
cols <- range(col2int(cols))
532+
cols <- range(cols)
530533

531534
sqref <- paste0(int2col(cols), rows)
532535
sqref <- stringi::stri_join(sqref, collapse = ":", sep = " ")
@@ -582,8 +585,13 @@ wbWorksheet <- R6::R6Class(
582585
#' @return The `wbWorkbook` object, invisibly
583586
unmerge_cells = function(rows = NULL, cols = NULL) {
584587

588+
cols <- col2int(cols)
589+
590+
if (length(cols) > 2 && any(diff(cols) != 1))
591+
warning("cols > 2, will create range from min to max.")
592+
585593
rows <- range(as.integer(rows))
586-
cols <- range(col2int(cols))
594+
cols <- range(cols)
587595

588596
sqref <- paste0(int2col(cols), rows)
589597
sqref <- stringi::stri_join(sqref, collapse = ":", sep = " ")

R/deprecate.R

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,26 @@
66
#' @name comment_internal
77
NULL
88

9+
#' Create a comment
10+
#'
11+
#' Use [wb_comment()] in new code. See [openxlsx2-deprecated]
12+
#'
13+
#' @inheritParams wb_comment
14+
#' @param author A string, by default, will use "user"
15+
#' @param visible Default: `TRUE`. Is the comment visible by default?
16+
#' @keywords internal
17+
#' @returns a `wbComment` object
18+
#' @export
19+
create_comment <- function(text,
20+
author = Sys.info()[["user"]],
21+
style = NULL,
22+
visible = TRUE,
23+
width = 2,
24+
height = 4) {
25+
.Deprecated("wb_comment()", old = "create_comment()")
26+
wb_comment(text = text, author = author, style = style, visible = visible, width = width[1], height = height[1])
27+
}
28+
929
#' @rdname comment_internal
1030
#' @inheritParams wb_add_comment
1131
#' @param comment An object created by [create_comment()]

man/create_comment.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-base_font.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ test_that("get_base_font works", {
1212
)
1313
)
1414

15-
wb$set_base_font(fontSize = 9, fontName = "Arial", fontColour = wb_colour("red"))
15+
wb$set_base_font(font_size = 9, font_name = "Arial", font_colour = wb_colour("red"))
1616
expect_equal(
1717
wb$get_base_font(),
1818
list(

tests/testthat/test-class-color.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,18 @@ test_that("tabColour can be wb_colour()", {
2121
expect_silent(
2222
wb_workbook()$
2323
# wb_colour
24-
add_worksheet(tabColour = wb_colour("green"))$
25-
add_chartsheet(tabColour = wb_colour("green"))$
24+
add_worksheet(tab_colour = wb_colour("green"))$
25+
add_chartsheet(tab_colour = wb_colour("green"))$
2626
# colour name
27-
add_worksheet(tabColour = "green")$
28-
add_chartsheet(tabColour = "green")
27+
add_worksheet(tab_colour = "green")$
28+
add_chartsheet(tab_colour = "green")
2929
)
3030
})
3131

3232
test_that("treat color and colour equally", {
3333

3434
wb_color <- wb_workbook() %>%
35-
wb_add_worksheet(tabColor = "green") %>%
35+
wb_add_worksheet(tab_color = "green") %>%
3636
wb_add_fill(color = wb_color("blue")) %>%
3737
wb_add_border(
3838
dims = "G12:H13",
@@ -43,7 +43,7 @@ test_that("treat color and colour equally", {
4343
)
4444

4545
wb_colour <- wb_workbook() %>%
46-
wb_add_worksheet(tabColour = "green") %>%
46+
wb_add_worksheet(tab_colour = "green") %>%
4747
wb_add_fill(colour = wb_colour("blue")) %>%
4848
wb_add_border(
4949
dims = "G12:H13",

tests/testthat/test-class-comment.R

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,35 @@ test_that("class wbComment works", {
55
})
66

77
test_that("wb_comment and create_comment are the same except for the different defaults", {
8-
c1 <- create_comment("x1", author = "")
8+
expect_warning(c1 <- create_comment("x1", author = ""), "deprecated")
99
c1_wb <- wb_comment("x1", visible = TRUE, author = "")
1010
expect_equal(c1, c1_wb)
1111
# create_comment drops multiple widths and heights silently.
1212
# wb_comment errors in this case
13-
expect_silent(create_comment(text = "x", author = "", width = c(1, 2)))
13+
expect_warning(create_comment(text = "x", author = "", width = c(1, 2)), "deprecated")
1414
expect_error(wb_comment(text = "x", author = "", width = c(1, 2)), "width must be a single")
1515

1616
})
1717

1818
test_that("create_comment() works", {
1919
# error checking
20-
expect_silent(create_comment("hi", width = 1))
21-
expect_silent(create_comment("hi", width = 1L))
22-
expect_silent(create_comment("hi", width = c(1, 2)))
23-
expect_silent(create_comment("hi", width = 1:2))
20+
expect_warning(create_comment("hi", width = 1), "deprecated")
21+
expect_warning(create_comment("hi", width = 1L), "deprecated")
22+
expect_warning(create_comment("hi", width = c(1, 2)), "deprecated")
23+
expect_warning(create_comment("hi", width = 1:2), "deprecated")
2424
expect_error(wb_comment("hi", width = 1:2), regexp = "width must be a")
2525

26-
expect_silent(create_comment("hi", height = 1))
27-
expect_silent(create_comment("hi", height = 1L))
28-
expect_silent(create_comment("hi", height = 1:2))
26+
expect_warning(create_comment("hi", height = 1), "deprecated")
27+
expect_warning(create_comment("hi", height = 1L), "deprecated")
28+
expect_warning(create_comment("hi", height = 1:2), "deprecated")
2929
expect_error(wb_comment("hi", height = 1:2))
30-
expect_error(create_comment("hi", visible = NULL))
31-
expect_error(create_comment("hi", visible = c(TRUE, FALSE)))
30+
expect_warning(expect_error(create_comment("hi", visible = NULL)), "deprecated")
31+
expect_warning(expect_error(create_comment("hi", visible = c(TRUE, FALSE))), "deprecated")
3232

33-
expect_error(create_comment("hi", author = 1))
34-
expect_error(create_comment("hi", author = c("a", "a")))
33+
expect_warning(expect_error(create_comment("hi", author = 1)), "deprecated")
34+
expect_warning(expect_error(create_comment("hi", author = c("a", "a"))), "deprecated")
3535

36-
expect_s3_class(create_comment("Hello"), "wbComment")
36+
expect_warning(expect_s3_class(create_comment("Hello"), "wbComment"), "deprecated")
3737
})
3838

3939

@@ -43,17 +43,17 @@ test_that("comments", {
4343
wb$add_worksheet("Sheet 1")
4444

4545
# write comment without author
46-
c1 <- create_comment(text = "this is a comment", author = "")
46+
c1 <- wb_comment(text = "this is a comment", author = "")
4747
wb <- wb_add_comment(wb, 1, dims = "B10", comment = c1)
4848

4949
# Write another comment with author information
50-
c2 <- create_comment(text = "this is another comment", author = "Marco Polo")
50+
c2 <- wb_comment(text = "this is another comment", author = "Marco Polo")
5151
wb <- wb_add_comment(wb, 1, dims = "C10", comment = c2)
5252

5353
# write a styled comment with system author
5454
s1 <- create_font(b = "true", color = wb_colour(hex = "FFFF0000"), sz = "12")
5555
s2 <- create_font(color = wb_colour(hex = "FF000000"), sz = "9")
56-
c3 <- create_comment(text = c("This Part Bold red\n\n", "This part black"), style = c(s1, s2))
56+
c3 <- wb_comment(text = c("This Part Bold red\n\n", "This part black"), style = c(s1, s2))
5757

5858
expect_silent(wb$add_comment(1, dims = "F1", comment = c3))
5959

@@ -74,7 +74,7 @@ test_that("comments", {
7474
wb$add_worksheet()
7575

7676
# write comment without author
77-
c1 <- create_comment(text = "this is a comment", author = "", visible = FALSE)
77+
c1 <- wb_comment(text = "this is a comment", author = "")
7878
wb$add_comment(dims = "B10", comment = c1)
7979

8080
expect_silent(wb$save(tmp))
@@ -97,7 +97,7 @@ test_that("load comments", {
9797
unlink(tempd, recursive = TRUE)
9898

9999
## add a new comment to a workbook that has comments
100-
c1 <- create_comment(text = "this is a comment", author = "")
100+
expect_warning(c1 <- create_comment(text = "this is a comment", author = ""), "deprecated")
101101
expect_silent(wb$add_comment(5, dims = "B10", comment = c1))
102102

103103
wb$save(temp)
@@ -113,7 +113,7 @@ test_that("load comments", {
113113

114114
test_that("wb_add_comment", {
115115

116-
c1 <- create_comment(text = "this is a comment", author = "")
116+
expect_warning(c1 <- create_comment(text = "this is a comment", author = ""), "deprecated")
117117

118118
wb <- wb_workbook()$add_worksheet()$add_comment(dims = "A1", comment = c1)
119119

@@ -155,7 +155,7 @@ test_that("wb_add_comment() works without supplying a wbComment object.", {
155155

156156
test_that("wb_remove_comment", {
157157

158-
c1 <- create_comment(text = "this is a comment", author = "")
158+
expect_warning(c1 <- create_comment(text = "this is a comment", author = ""), "deprecated")
159159
wb <- wb_workbook()$
160160
add_worksheet()$
161161
add_comment(dims = "A1", comment = c1)$
@@ -179,8 +179,10 @@ test_that("wb_remove_comment", {
179179

180180
test_that("print comment", {
181181

182-
c2 <- create_comment(text = "this is another comment",
183-
author = "Marco Polo")
182+
expect_warning(
183+
c2 <- create_comment(text = "this is another comment",
184+
author = "Marco Polo"),
185+
"deprecated")
184186
got <- capture_output(print(c2), print = TRUE)
185187
exp <- "Author: Marco Polo\nText:\n Marco Polo:\nthis is another comment\n\nStyle:\n\n\n\n\nFont name: Aptos Narrow\nFont size: 11\nFont color: #000000\n\n"
186188
expect_equal(got, exp)
@@ -190,7 +192,7 @@ test_that("print comment", {
190192
test_that("removing comment sheet works", {
191193

192194
temp <- temp_xlsx()
193-
c1 <- create_comment(text = "this is a comment", author = "")
195+
expect_warning(c1 <- create_comment(text = "this is a comment", author = ""), "deprecated")
194196

195197
wb <- wb_workbook()$
196198
add_worksheet("Sheet 1")$
@@ -206,7 +208,7 @@ test_that("fmt_txt in comment", {
206208

207209
tmp <- temp_xlsx()
208210
txt <- fmt_txt("Hello ", bold = TRUE) + fmt_txt("World")
209-
c1 <- create_comment(text = txt, author = "bla")
211+
expect_warning(c1 <- create_comment(text = txt, author = "bla"), "deprecated")
210212

211213
wb <- wb_workbook()$add_worksheet()$add_comment(dims = "B10", comment = c1)
212214
expect_silent(wb$save(tmp))

tests/testthat/test-class-hyperlink.R

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ test_that("encode Hyperlink works", {
66
formula_new <- '=HYPERLINK("#Tab_1!" & CELL("address", INDEX(C1:F1, MATCH(A1, C1:F1, 0))), "Go to the selected column")'
77

88
wb <- wb_workbook()$
9-
add_worksheet("Tab_1", zoom = 80, gridLines = FALSE)$
10-
add_data(x = rbind(2016:2019), dims = "C1:F1", colNames = FALSE)$
11-
add_data(x = 2017, dims = "A1", colNames = FALSE)$
9+
add_worksheet("Tab_1", zoom = 80, grid_lines = FALSE)$
10+
add_data(x = rbind(2016:2019), dims = "C1:F1", col_names = FALSE)$
11+
add_data(x = 2017, dims = "A1", col_names = FALSE)$
1212
add_data_validation(dims = "A1", type = "list", value = '"2016,2017,2018,2019"')$
1313
add_formula(dims = "B1", x = formula_old)$
1414
add_formula(dims = "B2", x = formula_new)
@@ -19,16 +19,16 @@ test_that("encode Hyperlink works", {
1919
got <- wb$worksheets[[1]]$sheet_data$cc["12", "f"]
2020
expect_equal(formula_old, got)
2121

22-
expect_equal(formula_new, wb_to_df(wb, colNames = FALSE, showFormula = TRUE)[1, "B"])
22+
expect_equal(formula_new, wb_to_df(wb, col_names = FALSE, show_formula = TRUE)[1, "B"])
2323

2424
})
2525

2626
test_that("formulas with hyperlinks works", {
2727

2828
wb <- wb_workbook()$
29-
add_worksheet("Tab_1", zoom = 80, gridLines = FALSE)$
30-
add_data(dims = "C1:F1", x = rbind(2016:2019), colNames = FALSE)$
31-
add_data(x = 2017, startCol = 1, startRow = 1, colNames = FALSE)$
29+
add_worksheet("Tab_1", zoom = 80, grid_lines = FALSE)$
30+
add_data(dims = "C1:F1", x = rbind(2016:2019), col_names = FALSE)$
31+
add_data(x = 2017, start_col = 1, start_row = 1, col_names = FALSE)$
3232
add_data_validation(dims = "A1", type = "list", value = '"2016,2017,2018,2019"')$
3333
add_formula(dims = "B1", x = '=HYPERLINK("#Tab_1!" & CELL("address", INDEX(C1:F1, MATCH(A1, C1:F1, 0))), "Go to the selected column")')$
3434
add_formula(dims = "B2", x = '=IF(2017 = VALUE(A1), HYPERLINK("github.com","github.com"), A1)')

0 commit comments

Comments
 (0)