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_set_row_heights: replacement has N rows, data has N-1 at row 100000 #1167

Closed
Arthfael opened this issue Oct 29, 2024 · 3 comments · Fixed by #1170
Closed

wb_set_row_heights: replacement has N rows, data has N-1 at row 100000 #1167

Arthfael opened this issue Oct 29, 2024 · 3 comments · Fixed by #1170

Comments

@Arthfael
Copy link

Arthfael commented Oct 29, 2024

I am writing large Excels with this package. As discussed with you here some time ago ( https://github.com/JanMarvin/openxlsx2/discussions ), I tested a parallel approach to building the table. I rewriting my old code, I encountered a weird error: I tried to set row_heights and the following call:
> WB <- openxlsx2::wb_set_row_heights(WB, SheetName, rws, 15) # rws = indices of the targe rows
failed for only one of my 55 parallel chunks, with an error of the type replacement has N rows, data has N-1 at row 100000
Downstream investigations revealed that this happened specifically when row 100000 was included in rws. More puzzling, functionally equivalent but syntactically different ways to pass rws make the difference between success and failure.

Below is a reprex:

WB <- wb_workbook()
WB <- wb_add_worksheet(WB, "test")
dat <- as.data.frame(matrix(rep(1, 10*2000), ncol = 10)) # Simple data to show that the problem is not caused by weird cell content
OS <- 99000
rws <- 1:2000 + OS
WB <- openxlsx2::wb_add_data_table(WB, "test", dat,
                                   dims = wb_dims(OS+1, 1),
                                   col_names = FALSE,
                                   table_style = "TableStyleMedium2",
                                   banded_rows = TRUE,
                                   banded_cols = FALSE)
WB <- openxlsx2::wb_set_row_heights(WB, "test", rws, 20) # -> Doesn't work
WB <- openxlsx2::wb_set_row_heights(WB, "test", min(rws):max(rws), 20) # -> Works
all.equal(rws, min(rws):max(rws)) # -> TRUE
identical(rws, min(rws):max(rws)) # -> FALSE
# Let's try with just a few rows (I typically work my way down using increasingly small row subsets to identify the offending one):
WB <- openxlsx2::wb_set_row_heights(WB, "test", c(99997, 99998, 99999), 20) # -> Works this time!
WB <- openxlsx2::wb_set_row_heights(WB, "test", 99997:99999, 20) # -> Works
# This only occurs if row 100000 is included in the range
WB <- openxlsx2::wb_set_row_heights(WB, "test", c(99999, 100000, 100001), 20) # -> Doesn't work
WB <- openxlsx2::wb_set_row_heights(WB, "test", c(99997, 99998, 99999) + 1, 20) # -> Also doesn't work
WB <- openxlsx2::wb_set_row_heights(WB, "test", 99999:100001, 20) # -> Works

Now, I just recently found out about ALTREPs, and whilst this is something I am absolutely not familiar with, this feels like it could be the cause. The 100000 feels like a boundary where R might change the underlying data representation, resulting in breaking the code here.

@Arthfael Arthfael changed the title wb_set_row_heights: replacement has N rows, data has N-1 around row 100000 wb_set_row_heights: replacement has N rows, data has N-1 at row 100000 Oct 29, 2024
@JanMarvin
Copy link
Owner

Hi @Arthfael, thanks for the report. It’s a bit simpler, but nevertheless a bug.

as.character(100000)
#> "1e+05"

In our row table we search for "100000".

@Arthfael
Copy link
Author

Arthfael commented Oct 29, 2024 via email

@JanMarvin
Copy link
Owner

I've added a PR in #1170. as.character(as.integer(rows)) should not break.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants