user3621202 user3621202 - 1 year ago 130
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 -

Any help would be much appreciated.

Answer Source

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:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download