user3621202 user3621202 - 15 days ago 8
R Question

Having a hard time understanding file locations on Mac in R

So I'm following a tutorial on making a word cloud with R. This is the first time getting back into programming for me in a long time and Im having issues with file directories and file locations to start.

> cname <- file.path(".","corpus","target")
> library (tm)
> docs <- Corpus(DirSource(cname))
Error in DirSource(cname) : empty directory


I placed the file at the Mac root drive and assumed thats what that location meant (/corpus/target) but it reads that its not being found.

This is the tutorial in question - http://www.analyticsvidhya.com/blog/2014/05/build-word-cloud-text-mining-tools/?utm_source=Linkedinstatus&utm_medium=Social&utm_campaign=070514

Any help would be much appreciated.

Answer

Change the first parameter to empty string:

cname <- file.path("", "corpus", "target")

This will correctly give the absolute path from the filesystem root, /corpus/target on a Mac.

After that, confirm that you have the right directory with:

list.files(cname)
Comments