openxlsx2 icon indicating copy to clipboard operation
openxlsx2 copied to clipboard

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

Open jmbarbone opened this issue 2 years ago • 2 comments

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)
}

jmbarbone avatar Mar 16 '22 01:03 jmbarbone

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.

JanMarvin avatar Mar 16 '22 10:03 JanMarvin

A fun = read.csv arg might suffice

jmbarbone avatar Mar 16 '22 13:03 jmbarbone