AU-BCE-EE / R-tips

Collection of tips for R users
GNU General Public License v3.0
0 stars 0 forks source link

R options for reading from Excel files #1

Open sashahafner opened 1 year ago

sashahafner commented 1 year ago

What do you use to read from Excel files? Usually I can avoid using Excel, and just use csv files instead. Those files are small, simple, and Git can track individual changes (unlike in spreadsheets, where even a small change means a whole new version will be saved). But sometimes a spreadsheet is the easiest option, e.g., when there are several files or sheets for inputs, and they are frequently changed. Which functions/packages work best?

One of you introduced me to openxlsx::read.xlsx() and that seems pretty simple.

A completely different approach is to turn the Excel file to csv first with a command-line utility. This can even be done in R with system(), in case the original Excel file is regularly changed.

system('xlsx2csv ../dat.xlsx -s 2 > ../csv/dat.csv')

That's actually a Python script that does the work from here: https://github.com/dilshod/xlsx2csv

sashahafner commented 1 year ago

I see we used read_xlsx() from the readxl package as well.