Reputation: 1277
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.
Upvotes: 7
Views: 41064
Reputation: 17412
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:
Mac OS X:
write.table(foo, file="/users/name/folder/filename.ext")
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
.
Upvotes: 8
Reputation: 8267
Sure:
write.table(foo,file="../bar/baz.txt")
Or you can use absolute paths - nomenclature will depend on your operating system.
Upvotes: 3