无法将数据导出到R(write.csv)中的文件 [英] Cannot export data to a file in R (write.csv)
问题描述
我正在尝试将R中的数据导出到csv文件中,并且尽可能简单,我总是收到相同的错误消息。例如:
I am trying to export data in R to a csv file, and as much simple as I try to do it, I always get the same error message. Example:
我创建一个简单的数据向导导出
I create a simple data vector to export
x <- c(1,3,4,3,5,7,5,8,2,5,7)
我尝试导出:
write.csv(x,file='whatever.csv')
我收到错误:
error in file(file ifelse (append a w )) cannot open the connection
In addition: Warning message: In file(file, ifelse(append, "a", "w")) :
cannot open file 'whatever.csv': Permission denied
解决这个问题?
推荐答案
第一部分是检查工作目录,并确保您具有对该目录的写入权限。您可以使用 getwd()
检查。我可以通过尝试写入只读目录来重现您的错误。
First part is to check the working directory and ensure that you have write access to that directory. You can check this with getwd()
. I can reproduce your error by trying to write to a directory which is read only.
要将工作目录设置为具有读取访问权限的其他目录,您可以键入 setwd( H:/ foo 的)
。
一旦你有写入权限, write.csv(x,file ='whatever.csv')
应该可以工作。
To set the working directory to something else with read access you can type setwd("H:/foo")
.
Once you have write access the write.csv(x,file='whatever.csv')
should work.
这篇关于无法将数据导出到R(write.csv)中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!