NeverBe NeverBe - 11 months ago 36
R Question

Where is my output text file from an R-script run in unix?

I am using R on a Unix system. I wrote an R script in windows, and uploaded it to Unix (via putty), such that I could run the script in R (in unix) with the command


Now, here is the problem. In my R script, I wrote
write.table(myDataOutput, file = "/myfolder/wantedData.txt")
as my output, but after running the script, the text file is nowhere to be found (not in any folder).

I did some research on google, but it seemed that my question is kind of too specific, and I did not manage to find a similar problem.

Please help me. Thank you!

ps: now the slash is updated. Sorry for the confusion.

Answer Source

I have had this problem myself, not being able to figure out the default directory which R uses for a file with a relative path. Since you used an absolute path, the file should be found at \myfolder\wantedData.txt. If it isn't there, you can try searching for it:

sudo find . -name 'wantedData.txt`

If this search comes up empty, then R did not write the file. If you find it, but in a location which you did not expect, then most likely R interpreted your path as a relative, rather than absolute, path. In this case, remember the location so you can find your file next time.


Based on the warning message you got from Unix, I would guess that your R script does not have permissions to write the output file in the location you specified. You could try running the R script with sudo, which might get around this problem.