JanMarvin / openxlsx2

openxlsx2 - read, write and modify xlsx files
https://janmarvin.github.io/openxlsx2/
Other
121 stars 11 forks source link

magic `csv_to_wb()` and `csv_to_xlsx()` functions? #93

Open jmbarbone opened 2 years ago

jmbarbone commented 2 years ago

Simple but would probably be pretty useful. I know I've saved many files as both csv and xlsx. A function that can can be passed a csv file (or files) that will convert it into an workbook and then another step for the xlsx. Probably don't need too many options (we'll have plenty of global options to control for a lot of areas) since this workflow is probably more oriented towards the "I should save these as an Excel file so coworkers can easily open them" instances.

Mock ups

csv_to_wb <- function(files, ...) {
  ls <- lapply(files, read.csv, ...)
  names(ls) <- names(files)
  wbWorkbook$new()$addWorksheet(ls)
}

Then we can have a nice converter.

csv_to_xlsx <- function(files, path, ...) {
  csv_to_wb(files, ...)$save(path = path)
}
JanMarvin commented 2 years ago

This has the tendency to open a can of worms. "But I need read.csv2, why can't you add vroom or readr? What about fwf or completely haven? Can you add arrow and what about sqlite?" We can add a few of the ones you've mentioned, but if it gets out of hand, we might exclude them into a separate helper package.

jmbarbone commented 2 years ago

A fun = read.csv arg might suffice