2

我第一次使用 R 我试图保存数据并再次加载它,我使用这个

> a <- 1:10
> save(a, file = "desktop/Data.Rdata")
> rm(a)
> load("desktop/Data.Rdata")

警告:

 cannot open compressed file 'desktop/Data.Rdata', probable reason 'No such file or directory'

请帮帮我。

工作的人

> a <- 1:10
> getwd()
[1] "C:/Users/saramachandran/Documents"
> save(a,file="Documents/sai.R")
Error in gzfile(file, "wb") : cannot open the connection
In addition: Warning message:
In gzfile(file, "wb") :
  cannot open compressed file 'Documents/sai.R', probable reason 'No such file or directory'
> save(a,file="/Documents/sai.R")
Error in gzfile(file, "wb") : cannot open the connection
In addition: Warning message:
In gzfile(file, "wb") :
  cannot open compressed file '/Documents/sai.R', probable reason 'No such file or directory'
> save(a,file="C:/Users/saramachandran/Documents/sai.R")
> rm(a)
> load("C:/Users/saramachandran/Documents/sai.R")
> print(a)
 [1]  1  2  3  4  5  6  7  8  9 10
> 
4

2 回答 2

8

尝试使用:

a <- 1:10
save(a, file = path.expand("~/desktop/Data.Rdata"))
rm(a)
load(path.expand("~/desktop/Data.Rdata"))

编辑:

您发布了以下内容...

> a <- 1:10
> getwd()
[1] "C:/Users/saramachandran/Documents"
> save(a,file="Documents/sai.R")
Error in gzfile(file, "wb") : cannot open the connection
In addition: Warning message:
In gzfile(file, "wb") :
  cannot open compressed file 'Documents/sai.R', probable reason 'No such file or directory'
> save(a,file="/Documents/sai.R")

问题是工作目录已经在 Documents 中。所以你试图保存到:

 C:/Users/saramachandran/Documents/Documents

这不存在。

改用它(或明确说明您发现的路径):

a <- 1:10
save(a, file = "Data.Rdata")
rm(a)
load("Data.Rdata")
于 2013-04-03T19:59:09.473 回答
1

我有几次同样的错误。我通过将我的项目设置为工作目录来解决它。单击您的项目 - 更多 - 下拉菜单并选择“设置为工作目录”。希望这有帮助,祝你好运。

于 2016-05-09T12:31:31.177 回答