extract_excel: A function that extracts all '.xls[x]' files in a folder

Description Usage Arguments Details Value Examples

Description

Store all data in one list of lists (ie one list of workbooks, each workbook is a list of sheets, each sheet is a dataframe (or an error message if applicable))

Usage

1
extract_excel(folder, general_case = NULL, weird_cases = NULL)

Arguments

folder

Path to folder

general_case

Args to be passed to readxl::read_excel for all sheets of all workbooks. Defaults to NULL.

weird_cases

Args to be passed to readxl::read_excel for specific sheets. Overwrites general_case. Defaults to NULL. See Details.

Details

general_case is one flat list of args (lines to skip and the like) to be passed to readxl::read_excel for all sheets. weird_cases is a nested list of such args for known specific cases. It is recommended you try to read the data without these argument at first, and then make adjustments according to outputs. The nested structure of weird_cases is wb (basename of Excel file) then sheet (name of a sheet) then args. See Examples. You may specify neither or one or both. If you specify both, general_cases is used and weird_cases overwrites it only where applicable.

Value

data A list of workbooks, each is a list of sheets as dataframes

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
## Not run: 
# Where your Excel files are located
folder <- "./excel data/"

# First try without parameters
data_ <- extract_excel(folder)

# View all data
view_excel(data_)

# Second try with adjustments where things went wrong
weird_cases <- list(
  "first workbook.xls" = list(
    "sheet2" = list(skip = 3),
    "sheet3" = list(skip = 2)
  ),
  "wb2.xlsx" = list(
    "tab2" = list(skip = 3, col_names = FALSE)
  )
)
data_ <- extract_excel(folder, weird_cases)

## End(Not run)

eaurele/xlutils3 documentation built on May 15, 2019, 7:28 p.m.