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

create initialize_cell function #545

Merged
merged 7 commits into from
Feb 16, 2023
Merged

create initialize_cell function #545

merged 7 commits into from
Feb 16, 2023

Conversation

JanMarvin
Copy link
Owner

@JanMarvin JanMarvin commented Feb 16, 2023

@cvaldezerea if you want to have a look, this branch should be much faster than the previous solution. But this is highly experimental and needs some more thinking

We have to avoid duplicated cell entries and should never remove cells that are already available in the workbook. Testing this is highly appreciated.

library(openxlsx2)

mm <- matrix(NA, ncol = 26, nrow = 100)

# write data and add color
beg <- Sys.time()
wb <- wb_workbook()$add_worksheet()
wb$add_data(x = mm, colNames = FALSE, na.strings = NULL)
wb$add_fill(dims = "A1:Z100", color = wb_color("yellow"))
end <-  Sys.time()
end - beg
#> Time difference of 0.1001139 secs

# write no data and add color
beg <- Sys.time()
wb <- wb_workbook()$add_worksheet()
wb$add_fill(dims = "A1:Z100", color = wb_color("yellow"))
end <-  Sys.time()
end - beg
#> Time difference of 0.007579803 secs

# workbook has 4 cells, add the remaining cells
beg <- Sys.time()
wb <- wb_workbook()$add_worksheet()
wb$add_data(dims = "A1", x = 1, colNames = FALSE)
wb$add_data(dims = "A100", x = 1, colNames = FALSE)
wb$add_data(dims = "Z1", x = 5, colNames = FALSE)
wb$add_data(dims = "Z100", x = 5, colNames = FALSE)
wb$add_fill(dims = "A1:Z100", color = wb_color("yellow"))
end <-  Sys.time()
end - beg
#> Time difference of 0.01585579 secs

@JanMarvin
Copy link
Owner Author

I'm a bit surprised that the first function is the slowest, but that might be spurious.

@JanMarvin
Copy link
Owner Author

library(openxlsx2)

beg <- Sys.time()
wb <- wb_workbook()$add_worksheet()
wb$add_fill(dims = "A1:Z10000", color = wb_color("yellow"))
end <-  Sys.time()
end - beg
#> Time difference of 0.5600958 secs


mm <- matrix(NA, ncol = 26, nrow = 10000)

beg <- Sys.time()
wb <- wb_workbook()$add_worksheet()
wb$add_data(x = mm, colNames = FALSE, na.strings = NULL)
wb$add_fill(dims = "A1:Z10000", color = wb_color("yellow"))
end <-  Sys.time()
end - beg
#> Time difference of 0.4300249 secs


beg <- Sys.time()
wb <- wb_workbook()$add_worksheet()
wb$add_data(dims = "A1", x = 1, colNames = FALSE)
wb$add_data(dims = "A10000", x = 1, colNames = FALSE)
wb$add_data(dims = "Z1", x = 5, colNames = FALSE)
wb$add_data(dims = "Z10000", x = 5, colNames = FALSE)
wb$add_fill(dims = "A1:Z10000", color = wb_color("yellow"))
end <-  Sys.time()
end - beg
#> Time difference of 1.290522 secs

@JanMarvin JanMarvin merged commit 1a4ac70 into main Feb 16, 2023
@JanMarvin JanMarvin deleted the speedup_cell_init branch February 16, 2023 22:55
@JanMarvin
Copy link
Owner Author

Needs further testing, but that can be done from the main branch as well.

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 this pull request may close these issues.

None yet

1 participant