[英]write.table to new directory
Is there any way to use write() and write.table() so that the output file is in a different directory than the working directory? 有没有办法使用write()和write.table(),以便输出文件与工作目录不在同一个目录中? It tried setting the path to the output file before the filename, and just get an error message.
它尝试在文件名之前设置输出文件的路径,只是得到一条错误消息。
If you're using windows, R
will know to go outside the current directory if it sees C:/
first (presumably other mounted drives too). 如果您正在使用Windows,如果它看到
C:/
first(也可能是其他已安装的驱动器), R
将知道在当前目录之外。 With Macs it will go outside the current wd if it sees /
. 对于Mac,如果它看到
/
它将超出当前的wd。 So: 所以:
Mac OS X: 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
. 因此,如果您在
/users/parent/subdir
并且想要在parent
引用某些内容,则必须输出完整路径 - write.table(foo, "parent/name.ext")
将告诉R创建一个文件: /users/parent/subdir/parent/name.ext
。
Sure: 当然:
write.table(foo,file="../bar/baz.txt")
Or you can use absolute paths - nomenclature will depend on your operating system. 或者您可以使用绝对路径 - 命名将取决于您的操作系统。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.