'Use R to open split archive files into excel and save them

I have a folder on a network drive that contains split archive files with the extension 001, 002, 003.....etc

Each month I go to this folder, grab the first 6 files (001 - 006) and drag them into a blank excel spreadsheet. This opens 6 separate excel spreadsheets that I then save into my working directory.

I then have some R code that does what I want to the spreadsheets.

I would like to write some code that retrieves these 001, 002, 003......files and saves them as excel spreadsheets into my working directory automatically, for example;

  1. Go to folder on network drive
  2. Grab files 001, 002, 003, 004, 005, 006
  3. Save as excel spreadsheets into working directory

Is there a way to do this using R?

Thanks in advance.



Solution 1:[1]

I believe you are looking for something like this:

path <- 'N:/.../your_folder'

files <- list.files(path = path, pattern = '001|002|003|004|005|006', full.names = T)

open <- lapply(files, function(x) readxl::read_excel(x, ...)) 

# maybe stitch them together?
patched <- do.call(rbind, open) # or rather patched <- data.table::rbindlist(open)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1