I would like to programatically read in a moderate number of excel files, compile them to a single database, and print them to a new file. I generally use list.files()
and a for
loop to achieve this, but in this case there are a few files that I don't want to include in the data read. I don't want to move them from the directory as it is not my project to organize the data for.
Here's an example of much shorter filenames than the real ones. The filenames I'd like to remove include the strings "no" and "negative". I think the code speaks for itself.
library(tidyverse)
vec1 <- c('C:/yes/file.xlsx','C:/yes/file.xlsx','C:/yes/file.xlsx',
'C:/no/file.xlsx','C:/no/file.xlsx','C:/yes/file.xlsx',
'C:/yes/file.xlsx','C:/yes/file.xlsx','C:/negative/file.xlsx')
vec1
rm.files <- vec1 %>% str_locate(c('no')) %>% data.frame() %>%
coalesce(vec1 %>% str_locate('negative') %>% data.frame()) %>%
na.omit() %>%
rownames()
rm.files
With this index of filenames to remove from vec1
, I'd like to remove those filenames from the vector prior to the data read. In my mind I should be able to do something like this:
vec1[-c(rm.files)]