Skip to content

Commit 2186798

Browse files
committed
[formula] switch to named formula for registering of formulas
1 parent ea7906b commit 2186798

File tree

5 files changed

+7
-19
lines changed

5 files changed

+7
-19
lines changed

R/class-workbook-wrappers.R

+1-4
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,6 @@ wb_remove_timeline <- function(
696696
#' @param remove_cell_style Should we keep the cell style?
697697
#' @param enforce enforce dims
698698
#' @param shared shared formula
699-
#' @param name A function name to access the custom formula
700699
#' @param ... additional arguments
701700
#' @return The workbook, invisibly.
702701
#' @family workbook wrappers
@@ -723,7 +722,7 @@ wb_remove_timeline <- function(
723722
#' add_formula(x = "SUM($A2:A2)", dims = "A8:E12", shared = TRUE)
724723
#'
725724
#' # add a custom formula, first define it, then use it
726-
#' wb$add_formula(x = "_xlfn.LAMBDA(TODAY() - 1)", name = "YESTERDAY")
725+
#' wb$add_formula(x = c(YESTERDAY = "_xlfn.LAMBDA(TODAY() - 1)"))
727726
#' wb$add_formula(x = "=YESTERDAY()", dims = "A1", cm = TRUE)
728727
#'
729728
wb_add_formula <- function(
@@ -739,7 +738,6 @@ wb_add_formula <- function(
739738
remove_cell_style = FALSE,
740739
enforce = FALSE,
741740
shared = FALSE,
742-
name = NULL,
743741
...
744742
) {
745743
assert_workbook(wb)
@@ -755,7 +753,6 @@ wb_add_formula <- function(
755753
remove_cell_style = remove_cell_style,
756754
enforce = enforce,
757755
shared = shared,
758-
name = name,
759756
... = ...
760757
)
761758
}

R/class-workbook.R

+3-6
Original file line numberDiff line numberDiff line change
@@ -2466,7 +2466,6 @@ wbWorkbook <- R6::R6Class(
24662466
#' @param remove_cell_style if writing into existing cells, should the cell style be removed?
24672467
#' @param enforce enforce dims
24682468
#' @param shared shared formula
2469-
#' @param name name
24702469
#' @return The `wbWorkbook` object
24712470
add_formula = function(
24722471
sheet = current_sheet(),
@@ -2480,21 +2479,19 @@ wbWorkbook <- R6::R6Class(
24802479
remove_cell_style = FALSE,
24812480
enforce = FALSE,
24822481
shared = FALSE,
2483-
name = NULL,
24842482
...
24852483
) {
24862484

24872485
standardize_case_names(...)
24882486

2489-
if (!is.null(name)) {
2487+
if (!is.null(names(x))) {
24902488
assert_class(x, "character")
2491-
assert_named_region(x)
2492-
assert_class(name, "character")
2489+
assert_named_region(names(x))
24932490

24942491
xml <- xml_node_create(
24952492
"definedName",
24962493
xml_children = x,
2497-
xml_attributes = c(name = name)
2494+
xml_attributes = c(name = names(x))
24982495
)
24992496
private$append_workbook_field("definedNames", xml)
25002497

man/wbWorkbook.Rd

-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/wb_add_formula.Rd

+1-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-formulas.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,9 @@ test_that("increase formula dims if required", {
207207
test_that("registering formulas works", {
208208

209209
fml <- "_xlfn.LAMBDA(TODAY() - 1)"
210-
wb <- wb_workbook()$add_worksheet()$
211-
add_formula(x = fml, name = "YESTERDAY")
210+
wb <- wb_workbook()$add_worksheet()
212211

212+
expect_message(wb$add_formula(x = c(YESTERDAY = fml)), "formula registered to the workbook")
213213
expect_equal(wb$get_named_regions()$value, fml)
214214

215215
})

0 commit comments

Comments
 (0)