openxlsx2 icon indicating copy to clipboard operation
openxlsx2 copied to clipboard

internal `R6` workbook implementation functions

Open jmbarbone opened this issue 2 years ago • 3 comments

R/class-workbook.R has become quite massive (6000+ lines!)

This can be reduced by a little {R6} wrapper trick (yes, more wrappers). An example can be seen with the {desc} package: https://github.com/r-lib/desc/blob/main/R/description.R

method inside object:

set_value = function(wb, ...) {
  set_value_impl(self, private, ...)
}

function outside object:

set_value_impl <- function(self, private, ...) {
  # perform some actions
  ...
  self
}

Because self and private are environments, they can be modified wherever. This means we'd be able to pull these values into separate functions and save some of the more complex functions in separate files.

Essentially,

wb_function(wb, ...) calls wb$function(...) calls wb_function_impl(self, private, ...)

jmbarbone avatar Oct 29 '22 15:10 jmbarbone

@JanMarvin , if we have some other heavy lifting around the wbWorkbook class, I can try to knock this out in a weekend. It would present a lot of changes that would be hard/annoying to merge with any other development.

jmbarbone avatar Oct 29 '22 15:10 jmbarbone

Don't recall anything urgent from the top of my head regarding wbWorkbook. I was thinking about exporting a couple of wbWorkbook functions to individual functions similar to write_data() and write_data_table(). But if there are other options let's go for it. After 0.3.1 there are still enough things to work on :)

JanMarvin avatar Oct 29 '22 23:10 JanMarvin

There's ~some~ a dozen or so pending R6 issues that I haven't gotten to, so hopefully this sort of cleanup will make those a bit easier to manage. I don't think this will have any visible user changes, and should be pretty safe, too, unless I mess up.

jmbarbone avatar Nov 06 '22 17:11 jmbarbone