Skip to content

Instantly share code, notes, and snippets.

@przmv
Created July 2, 2020 13:47
Show Gist options
  • Save przmv/9e55d46ed5410e73e1f283a40e575158 to your computer and use it in GitHub Desktop.
Save przmv/9e55d46ed5410e73e1f283a40e575158 to your computer and use it in GitHub Desktop.
Convert all xls[x] files in the current directory to CSV
#!/usr/bin/env Rscript
library(readxl)
pattern <- ".xls[x]?$"
# Create a vector of Excel files to read
files_to_read = list.files(pattern=pattern)
# Read each file and write it to CSV
lapply(files_to_read, function(f) {
df <- read_excel(f)
write.csv(df, gsub(pattern, ".csv", f), row.names=FALSE)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment