Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wb_add_formula() requires dims of matching length #1130

Closed
JanMarvin opened this issue Sep 9, 2024 · 1 comment · Fixed by #1131
Closed

wb_add_formula() requires dims of matching length #1130

JanMarvin opened this issue Sep 9, 2024 · 1 comment · Fixed by #1131
Labels
bug 🐛 Something isn't working

Comments

@JanMarvin
Copy link
Owner

An unintended change in release 1.9 requires the user to specify a cell for each formula passed to wb_add_formula(). The workaround is to specify the dimensions where the formula is supposed to be written to, ahead of the formula.

library(openxlsx2)
packageVersion("openxlsx2")
#> [1] '1.9'

fml <- c("SUM(A2:B2)", "SUM(A3:B3)")
  
# broken, used to work
wb <- wb_workbook()$
  add_worksheet()$
  add_data(x = matrix(1:4, 2, 2))$
  add_formula(dims = "C2", 
              x = fml)
#> Error in `[<-.data.frame`(`*tmp*`, , value = c("SUM(A2:B2)", "SUM(A3:B3)": replacement has 2 rows, data has 1

# workaround
wb <- wb_workbook()$
  add_worksheet()$
  add_data(x = matrix(1:4, 2, 2))$
  add_formula(dims = wb_dims(x = fml, from_dims = "C2"), 
              x = fml)

if (interactive()) wb$open()
@JanMarvin JanMarvin added the bug 🐛 Something isn't working label Sep 9, 2024
@JanMarvin
Copy link
Owner Author

Closed in #1131

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant