1

I've got a folder full of .doc files and I want to merge them all into R to create a dataframe with filename as one column and content as another column (which would include all content from the .doc file.

Is this even possible? If so, could you provide me with an overview of how to go about doing this?

I tried starting out by converting all the files to .txt format using readtext() using the following code:

 DATA_DIR <- system.file("C:/Users/MyFiles/Desktop")
 readtext(paste0(DATA_DIR, "/files/*.doc"))

I also tried:

 setwd("C:/Users/My Files/Desktop")

I couldn't get either to work (output from R was Error in list_files(file, ignore_missing, TRUE, verbosity) : File '' does not exist.) but I'm not sure if this is necessary for what I want to do.

Sorry that this is quite vague; I guess I want to know first and foremost if what I want to do can be done. Many thanks!

Catherine Laing
  • 475
  • 6
  • 18
  • 1
    The actual code snippet would be helpful, including any packages you are using (I _think_ you're using the `readtext` package for that `readtext()` function but I'm unusually familiar with CRAN packages and most other R folks aren't as crazy as I am :-) – hrbrmstr Nov 05 '18 at 10:40
  • thanks @hrbrmstr - edited to show the code! – Catherine Laing Nov 05 '18 at 10:48
  • thanks for flagging this up @camille - it must not have saved. Edit properly now! – Catherine Laing Nov 05 '18 at 14:16
  • Are you sure about your file paths? Like if you manually enter a path to a file and read it successfully, is that definitely the same path as what you get from pasting? – camille Nov 05 '18 at 14:21
  • I'm not familiar with doing this with doc files, but there are other posts doing similar tasks with csv and other format files, such as [this one](https://stackoverflow.com/q/49831148/5325862) – camille Nov 05 '18 at 14:27
  • @camille I already know how to do it with csv files but it won't work for the .doc files that I want to convert, unfortunately – Catherine Laing Nov 05 '18 at 17:18
  • If that's something that you've tried that hasn't worked, it's probably a good addition to the question. Otherwise, it's hard to [reproduce](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – camille Nov 05 '18 at 17:46

0 Answers0