Search code examples
rtm

DirSource Import file issue


I have been trying to import the file

reuters <- Corpus(DirSource(directory = "E:\\R Programs\\Test\\Reuteurs\\reut2-000.xml", encoding = "UTF-8"), 
   readerControl = list(reader = readReut21578XMLasPlain))

However I get below error:

Error in DirSource(directory = "E:\\R Programs\\Test\\Reuteurs\\reut2-000.xml",  : 
  empty directory

I have also checked other solutions provide in stackoverflow but its not working for me. Am I missing anything?

But below code works: Why DirSource method is not working for me? Am I missing anything?

reuters <- Corpus(URISource("file://E:\\R Programs\\Test\\Reuteurs\\reut2-000.xml",encoding="UTF-8"), 
   readerControl = list(reader = readReut21578XMLasPlain))

Reference link which I referred:

R: Got problems in reading text file

Using R for Text Mining Reuters-21578

R Error in trying to access local data


Solution

  • reut2-000.xml probably is a file, and not a directory?

    Opening a file as directory will cause an error.