Skip to content

Commit

Permalink
[fmls] solve the test issue with cm formulas
Browse files Browse the repository at this point in the history
Merge branch 'trim_cc_variables' of github.com:JanMarvin/openxlsx2 into trim_cc_variables

# Conflicts:
#	R/write.R
  • Loading branch information
JanMarvin committed Jan 29, 2025
2 parents 27048da + 5529999 commit fb34ee6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 24 deletions.
16 changes: 0 additions & 16 deletions R/class-sheet-data.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,6 @@ wb_sheet_data <- function() {

# helpers -----------------------------------------------------------------

# Consider making some helpers for the cc stuff.

empty_sheet_data_cc <- function(n, slim = TRUE) {
nms <- c(
"r", "row_r", "c_r", "c_s", "c_t", "c_cm", "c_ph", "c_vm",
"v", "f", "f_attr", "is", "typ")
if (slim)
nms <- c(
"r", "row_r", "c_r", "c_s", "c_t",
"v", "f", "f_attr", "is", "typ")
create_char_dataframe(
colnames = nms,
n = n
)
}

empty_row_attr <- function(n) {
create_char_dataframe(
colnames = c("collapsed", "customFormat", "customHeight", "x14ac:dyDescent",
Expand Down
16 changes: 10 additions & 6 deletions R/write.R
Original file line number Diff line number Diff line change
Expand Up @@ -414,11 +414,15 @@ write_data2 <- function(
rows_attr$r <- rownames(rtyp)

# original cc data frame
cc <- empty_sheet_data_cc(n = nrow(data) * ncol(data), slim = TRUE)

if (any(dc == openxlsx2_celltype[["cm_formula"]])) {
cc$c_cm <- ""
}
has_cm <- if (any(dc == openxlsx2_celltype[["cm_formula"]])) "c_cm" else NULL
nms <- c(
"r", "row_r", "c_r", "c_s", "c_t", has_cm,
"v", "f", "f_attr", "is", "typ"
)
cc <- create_char_dataframe(
colnames = nms,
n = nrow(data) * ncol(data)
)

sel <- which(dc == openxlsx2_celltype[["logical"]])
for (i in sel) {
Expand Down Expand Up @@ -527,7 +531,7 @@ write_data2 <- function(
cc[["f_attr"]] <- sprintf("t=\"%s\"", "shared")
cc[1, "f_attr"] <- paste(cc[1, "f_attr"], sprintf("ref=\"%s\"", dims))
cc[["f_attr"]] <- paste(cc[["f_attr"]], sprintf("si=\"%s\"", int_si))
cc[2:nrow(cc), "f"] <- rep("", length(2:nrow(cc)))
cc[2:nrow(cc), "f"] <- ""
}

if (is.null(wb$worksheets[[sheetno]]$sheet_data$cc)) {
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-formulas.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ test_that("writing formulas with cell metadata works", {

exp <- data.frame(
r = "A1", row_r = "1", c_r = "A", c_s = "", c_t = "",
v = "", f = "SUM(ABS(A2:A11))",
c_cm = "1", v = "", f = "SUM(ABS(A2:A11))",
f_attr = "t=\"array\" ref=\"A1\"", is = "",
typ = "14", c_cm = "1",
typ = "14",
stringsAsFactors = FALSE)
got <- wb$worksheets[[1]]$sheet_data$cc[1, ]
expect_equal(exp, got)
Expand Down

0 comments on commit fb34ee6

Please sign in to comment.