Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

write.table to new directory

Tags:

r

Is there any way to use write() and write.table() so that the output file is in a different directory than the working directory? It tried setting the path to the output file before the filename, and just get an error message.

like image 455
user1815498 Avatar asked Nov 30 '12 19:11

user1815498


1 Answers

If you're using windows, R will know to go outside the current directory if it sees C:/ first (presumably other mounted drives too). With Macs it will go outside the current wd if it sees /. So:

  1. Mac OS X:

    write.table(foo, file="/users/name/folder/filename.ext")
    
  2. Windows

    write.table(foo, file="C:/users/name/folder/filename.ext")
    

Always test to make sure you have the path right first!

list.files("C:/...")
list.files("/....")       #Give errors if path doesn't exist as typed

So if you're in /users/parent/subdir and you want to reference something in parent, you must type out the full path - write.table(foo, "parent/name.ext") will tell R to make a file: /users/parent/subdir/parent/name.ext.

like image 194
Señor O Avatar answered Sep 25 '22 13:09

Señor O