0

I created a function extracting tables from docx files and combined them as one data set successfully with a sample folder of 4 docx files.

Then I linked the function to a folder with 500 files, and all of sudden, error came.

> lapply(files, FUN=docTodata) 
  Error: Cannot find 'marginversion1.docx' 

This is the code, and I omit here the middle of the path that has my name.

# read all files in a directory
files<-list.files(path="C:/Users/...../files")
print(files)

When printing files, it successfully prints all the file names in the folder!!!!! but lapply() does not read files.

rocknRrr
  • 341
  • 1
  • 10
  • No, it still says the same error. – rocknRrr Aug 16 '20 at 22:50
  • If you can show a small reproducible example, it can be tested – akrun Aug 16 '20 at 22:50
  • I added two example I created.. (but don; know how to link docx files to here) – rocknRrr Aug 16 '20 at 23:04
  • Have you tried a `for` loop i.e. `out <- vector('list', length(files)); for(i in seq_along(files)) out[[i]] <- docTodata(files[i])` – akrun Aug 16 '20 at 23:05
  • I guess the error showed would be an issue with some of the elements. You could wrap with `tryCatch` and check where it is going wrong – akrun Aug 16 '20 at 23:06
  • I tried to use loop but the it kept causing errors and simplified it.. sorry what is tryCatch? where should I have to put it? – rocknRrr Aug 16 '20 at 23:11
  • Hopefully [this](https://stackoverflow.com/questions/12193779/how-to-write-trycatch-in-r) should help for writing trycatch – akrun Aug 16 '20 at 23:12
  • 1
    Is your working directory identical with the one that contains the files? Otherwise maybe you need to use `files<-list.files(path="C:/Users/...../files", full.names = TRUE)` – user12728748 Aug 16 '20 at 23:51
  • Does the function work correctly with 1 file? What does `docTodata(files[1])` return? – Ronak Shah Aug 17 '20 at 01:01
  • @user12728748 omg this works!!! – rocknRrr Aug 17 '20 at 02:10

0 Answers0