Created
September 5, 2022 14:38
-
-
Save erikerhardt/5d8e681fa2c66dc3aa38ff459f8ac9d5 to your computer and use it in GitHub Desktop.
Read current (most recent) files in folder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Read current files | |
# Assumed file naming structure is Filename_YYYYMMDD.csv | |
# list of all files | |
fn_list_data_raw <- dir("data/") | |
# filenames to match | |
fn_dat_list_in <- | |
c( | |
"UNM-salary-book_20*.csv" | |
, "dat_ms_name_group_20*.csv" | |
) | |
# store current files here | |
fn_dat_current_list <- list() | |
# compare filenames to match with list of all files, keep most recent | |
for (i_file in seq_along(fn_dat_list_in)) { | |
fn_dat_current_list[[ i_file ]] <- | |
fn_list_data_raw[ | |
max( | |
which( | |
grepl( | |
glob2rx( | |
fn_dat_list_in[i_file] | |
) | |
, fn_list_data_raw | |
) | |
) | |
) | |
] | |
} | |
dat_one <- | |
readr::read_csv( | |
file = file.path("data", fn_dat_current_list[[ 1 ]]) | |
) | |
# etc. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment