Learn R Programming

xlutils3 (version 0.1.0)

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

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

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.

Value

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

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.

Examples

Run this code
## 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)

Run the code above in your browser using DataLab