Skip to content

Commit

Permalink
remove rows/cols from public API
Browse files Browse the repository at this point in the history
  • Loading branch information
JanMarvin committed Jul 19, 2023
1 parent 063ca7c commit 454dac2
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 34 deletions.
21 changes: 10 additions & 11 deletions R/class-workbook-wrappers.R
Original file line number Diff line number Diff line change
Expand Up @@ -3101,6 +3101,7 @@ wb_add_form_control <- function(
#' @param style A style to apply to those cells that satisfy the rule. Default is 'font_color = "FF9C0006"' and 'bgFill = "FFFFC7CE"'
#' @param type The type of conditional formatting rule to apply.
#' @param params Additional parameters passed. See **Details** for more
#' @param ... additional arguments
#' @details See Examples.
#'
#' @details
Expand Down Expand Up @@ -3165,8 +3166,6 @@ wb_add_conditional_formatting <- function(
wb,
sheet = current_sheet(),
dims = NULL,
cols = NULL,
rows = NULL,
rule = NULL,
style = NULL,
type = c(
Expand All @@ -3185,18 +3184,18 @@ wb_add_conditional_formatting <- function(
border = TRUE,
percent = FALSE,
rank = 5L
)
),
...
) {
assert_workbook(wb)
wb$clone()$add_conditional_formatting(
sheet = sheet,
dims = dims,
cols = cols,
rows = rows,
rule = rule,
style = style,
type = type,
params = params
sheet = sheet,
dims = dims,
rule = rule,
style = style,
type = type,
params = params,
... = ...
)
}

Expand Down
29 changes: 21 additions & 8 deletions R/class-workbook.R
Original file line number Diff line number Diff line change
Expand Up @@ -3874,18 +3874,15 @@ wbWorkbook <- R6::R6Class(
#' @description Add conditional formatting
#' @param sheet sheet
#' @param dims dims
#' @param cols cols
#' @param rows rows
#' @param rule rule
#' @param style style
#' @param type type
#' @param params Additional parameters
#' @param ... additional arguments
#' @returns The `wbWorkbook` object
add_conditional_formatting = function(
sheet = current_sheet(),
dims = NULL,
cols = NULL,
rows = NULL,
rule = NULL,
style = NULL,
# TODO add vector of possible values
Expand All @@ -3905,18 +3902,34 @@ wbWorkbook <- R6::R6Class(
border = TRUE,
percent = FALSE,
rank = 5L
)
),
...
) {

cols <- list(...)[["cols"]]
rows <- list(...)[["rows"]]

if (!is.null(rows) && !is.null(cols)) {

if (length(cols) > 2 && any(diff(cols) != 1))
warning("cols > 2, will create range from min to max.")

if (getOption("openxlsx2.soon_deprecated", default = FALSE))
.Deprecated(old = "cols/rows", new = "dims", package = "openxlsx2")

dims <- rowcol_to_dims(rows, cols)
}

ddims <- dims_to_rowcol(dims, as_integer = TRUE)
rows <- ddims[[2]]
cols <- ddims[[1]]

if (!is.null(style)) assert_class(style, "character")
assert_class(type, "character")
assert_class(params, "list")

type <- match.arg(type)

if (length(cols) > 2 && any(diff(cols) != 1))
warning("cols > 2, will create range from min to max.")

## rows and cols
if (!is.null(cols) && !is.null(rows)) {
if (!is.numeric(cols)) {
Expand Down
11 changes: 4 additions & 7 deletions man/wbWorkbook.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 8 additions & 7 deletions man/wb_add_conditional_formatting.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/testthat/test-conditional_formatting.R
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ test_that("containsErrors works", {
wb$add_data(x = c(1, NaN), colNames = FALSE)
wb$add_data(x = c(1, NaN), colNames = FALSE, startCol = 2)
wb$add_conditional_formatting(cols = 1, rows = 1:3, type = "containsErrors")
wb$add_conditional_formatting(col = 2, rows = 1:3, type = "notContainsErrors")
wb$add_conditional_formatting(cols = 2, rows = 1:3, type = "notContainsErrors")

exp <- c(
"<cfRule type=\"containsErrors\" dxfId=\"0\" priority=\"2\"><formula>ISERROR(A1:A3)</formula></cfRule>",
Expand Down

0 comments on commit 454dac2

Please sign in to comment.