I have a filename that contain many files of this type
filenames <- list.files(path= "~/GitHub/emmsa/input/prueba",
full.names = TRUE, pattern = "*.RDS", recursive = TRUE)
filenames
"C:/Users/gigar/Documents/GitHub/emmsa/input/test/prices_01_01_2014.RDS"
"C:/Users/gigar/Documents/GitHub/emmsa/input/test/prices_02_01_2014.RDS"
"C:/Users/gigar/Documents/GitHub/emmsa/input/test/prices_03_01_2014.RDS"
sites <- str_extract(filenames, ("[\\d{4}_\\d{2}_\\d{2}]+"))
[1] "_01_01_2014" "_02_01_2014" "_03_01_2014" "_04_01_2014" "_05_01_2014" "_06_01_2014"
I want to apply this formula that is in this https://stackoverflow.com/questions/46299777/add-filename-column-to-table-as-multiple-files-are-read-and-bound , for which I need to extract the date and convert it into a date column for each file. I want you to help me improve this code that I have been stuck with these results
filenames <- list.files(path, full.names = TRUE, pattern = fileptrn, recursive = TRUE)
sites <- str_extract(filenames, "[A-Z]{2}-[A-Za-z0-9]{3}") # same length as filenames
Pass chunk of filename to column name
I am stuck in the part of using regular expressions to be able to develop the code.
my goal is to get the date from the file name and add it as a date column to every file i have.
I would like you to support me in this regard, I know I'm close, but I can't find the solution. Thanks in advance