Recurse through subdirectories returning either filenames or tibbles (data.frames) by reading csv, xls, or xlsx with e_read_data_files().

e_read_data_subdir_into_lists(
  fn_path = ".",
  fn_detect = c("csv$", "xls$", "xlsx$"),
  sw_fn_or_dat = c("fn", "dat")[1],
  sw_exclude_empty_dir = c(TRUE, FALSE)[1],
  sw_dat_add_col_path_fn = c(TRUE, FALSE)[1],
  sw_dat_print_fn_read = c(TRUE, FALSE)[2],
  excel_sheets = "all",
  sw_clean_names = c(TRUE, FALSE)[2],
  sw_list_or_flat = c("list", "flat")[1],
  excel_range = NULL,
  excel_col_names = TRUE
)

Arguments

fn_path

Starting directory path

fn_detect

NULL for all. File specification, used by stringr::str_detect(), usually specifying file extensions.

sw_fn_or_dat

Return filenames or tibbles (data.frames)

sw_exclude_empty_dir

T/F exclude empty directories

sw_dat_add_col_path_fn

T/F for data, add two columns specifying the directory (DIR__) and filename (FILE__)

sw_dat_print_fn_read

T/F print file names and dimensions as the files are read

excel_sheets

"all" for all sheets, or a list of numbers "c(1, 2)"; applies to all excel sheets. Passed to e_read_data_files().

sw_clean_names

For data, T/F to clean column names using janitor::clean_names

sw_list_or_flat

Hierarical list or a "flat" 1-level list

excel_range

When reading Excel files, NULL reads entire sheet, a range is specified as in readxl::read_xlsx. Applies to all files.

excel_col_names

Specified as in readxl::read_xlsx. Applies to all files.

Value

fn_names Either a structured list of filenames or of tibbles

Examples

if (FALSE) {
# # all file names
# e_read_data_subdir_into_lists(
#     fn_path   = "./data-raw/dat_subdir"
#   , fn_detect = NULL
#   , sw_fn_or_dat  = c("fn", "dat")[1]
#   , sw_exclude_empty_dir = c(TRUE, FALSE)[1]
#   )
# # selected file names
# e_read_data_subdir_into_lists(
#     fn_path   = "./data-raw/dat_subdir"
#   , fn_detect = c("csv$", "xls$", "xlsx$")
#   , sw_fn_or_dat  = c("fn", "dat")[1]
#   , sw_exclude_empty_dir = c(TRUE, FALSE)[1]
#   )
# # selected data
# e_read_data_subdir_into_lists(
#     fn_path                 = "./data-raw/dat_subdir"
#   , fn_detect               = c("csv$", "xls$", "xlsx$")
#   , sw_fn_or_dat            = c("fn", "dat")[2]
#   , sw_exclude_empty_dir    = c(TRUE, FALSE)[1]
#   , sw_dat_add_col_path_fn  = c(TRUE, FALSE)[1]
#   , sw_dat_print_fn_read    = c(TRUE, FALSE)[1]
#   , sw_clean_names          = c(TRUE, FALSE)[2]
#   , sw_list_or_flat         = c("list", "flat")[1]
#   )
# # selected data, flatten the directory structure
# e_read_data_subdir_into_lists(
#     fn_path                 = "./data-raw/dat_subdir"
#   , fn_detect               = c("csv$", "xls$", "xlsx$")
#   , sw_fn_or_dat            = c("fn", "dat")[2]
#   , sw_exclude_empty_dir    = c(TRUE, FALSE)[1]
#   , sw_dat_add_col_path_fn  = c(TRUE, FALSE)[1]
#   , sw_dat_print_fn_read    = c(TRUE, FALSE)[1]
#   , sw_clean_names          = c(TRUE, FALSE)[2]
#   , sw_list_or_flat         = c("list", "flat")[2]
#   )
}