I have several PDF files in my directory. I have downloaded them previously, no big deal so far.
I want to read all those files in R. My idea was to use the "pdf_text" function from the "pdftools" package and write a formula like this:
mypdftext <- pdf_text(files)
Where "files" is an object that gathers all the PDF file names, so that I don't have to write manually all the names. Because I have actually downlaoded a lot of files, it would avoid me to write:
mypdftext <- pdf_text("file1.pdf", "file2.pdf", and many more files...)
To create the object "pdflist", I used "files <- list.files (pattern = "pdf$")" The “files” vector contains all the PDF file names.
But "files" does not work with pdf_text function, probably because it's a vector. What can I do instead?
Mapover the different file names:Map(pdf_text, files)and that will return a list. It depends on how exactly you want to combine all those files as to what you do next. - MrFlickapply-style function e.g.mypdftexts <- lapply(files, {function(x) pdf_text(x)}). This will return a list with each element being the text from a pdf file. - meenaparam