A set of functions to convert between CSV and XLSX formats using flexible input and output options.
Arguments
- file
Path or paths to input files. For
csv_to_wb(), users can pass multiple CSV files when creating a workbook or xlsx file. If these inputs are named, the names are used as worksheet names.- new_file
Path to output file. Optional. If
new_fileis not supplied andfileis a string,new_fileis set to use the same path with a new file extension or (if file is not a string)new_fileis set to a temporary file.- .f
Function used to read or write the csv file. Defaults to
utils::read.csvforcsv_to_wb()andcsv_to_xlsx()andutils::write.csvforxlsx_to_csv(). Other functions are allowed but must use the input or output file name as the second argument.- ...
Additional arguments passed to
.f- sheet
A sheet in the workbook specified by
file(either an index or a sheet name). Defaults to 1.- ext
File extension for output file. Defaults to "csv".
Details
These functions allow seamless conversion between CSV and XLSX formats:
csv_to_wb: Reads one or more CSV files and writes them to a workbook object.csv_to_xlsx: Converts one or more CSV files to a XLSX file.xlsx_to_csv: Converts an XLSX file to a CSV file.
Author
Jordan Mark Barbone jmbarbone@gmail.com
Jan Marvin Garbuszus jan.garbuszus@ruhr-uni-bochum.de
Eli Pousson eli.pousson@gmail.com
Examples
# Create example CSV file
csv <- tempfile(fileext = ".csv")
utils::write.csv(x = mtcars, file = csv)
# Convert CSV to Workbook
wb <- csv_to_wb(file = csv)
# Convert CSV to XLSX
xlsx <- openxlsx2::temp_xlsx()
csv_to_xlsx(file = csv, new_file = xlsx)
# Convert XLSX back to CSV
xlsx_to_csv(file = xlsx, new_file = csv)