I'm using the 'readtext' package to import multiple text files in a specific directory.
library(readtext)
DATA_DIR <- system.file("extdata/", package = "readtext")
readtext(paste0(DATA_DIR, "/txt/UDHR/*"))
My question is: is there any way to import text files based on their titles? I want to import files with titles containing a specific word, for example, apple.
Thank you for your help in advance.
This should do what you want.
In this silly example, I setup one parent folder which contains 3 sub-folders. In each sub-folder I have 5 text files: the_run1.txt, the_run2.txt, the_run3.txt, run1.txt, and run2.txt. I am hitting the parent folder and looking through all sub-folders for the text files that have 'the_run' in the name of the file. That's about it. I created a list of these 9 files (3 files in 3 folders), and looped through this list to load everything into a single data table.