错误保存:gzfile错误(文件," wb"):无法打开连接

时间:2016-10-25 12:54:18

标签: r save

我正在尝试在Rstudio 3.3.0上运行LDA主题分析。我正在执行以下步骤但仍然收到错误:

gzfile中的错误(文件," wb"):无法打开连接 另外:警告信息: 在gzfile(文件," wb")中:   无法打开压缩文件'结果/ Gibbs_5_1.rda',可能的原因'没有这样的文件或目录'

保存时出现问题。

D <- nrow(data)
folding <- sample(rep(seq_len(10), ceiling (D))[seq_len(D)]) 
for (k in topics)
{
  for (chain in seq_len(10))
     {
    FILE <- paste("Gibbs_", k, "_", chain, ".rda", sep = "")

    training <- LDA(data[folding != chain,], k = k,
    control = list(seed = SEED,
    burnin = BURNIN, thin = THIN, iter = ITER, best= BEST),
    method = "Gibbs")
    best_training <- training@fitted[[which.max(logLik(training))]]
    testing <- LDA(data[folding == chain,], model = best_training,
    control = list(estimate.beta = FALSE, seed = SEED,
    burnin = BURNIN, 
    thin = THIN, iter = ITER, best = BEST))

    save(training, testing, file = file.path("results", FILE))
  }
}

我的计算机上有足够的工作空间,我尝试重启r几次,是的,我查看了其他问题,但没有一个解决方案似乎有效。

> sessionInfo()
R version 3.3.0 (2016-05-03)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.10.5 (Yosemite)

locale:
[1] C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] topicmodels_0.2-4  wordcloud_2.5      RColorBrewer_1.1-2 slam_0.1-35        SnowballC_0.5.1   
[6] tm_0.6-2           NLP_0.1-9         

loaded via a namespace (and not attached):
[1] modeltools_0.2-21 parallel_3.3.0    tools_3.3.0       Rcpp_0.12.5       stats4_3.3.0    

我是R的初学者,我按照一本书对我的硕士论文进行分析。

谢谢!

1 个答案:

答案 0 :(得分:3)

错误消息显示无法保存文件。它试图保存什么?查看代码看起来它试图保存在名为"results"的文件夹中。这个文件夹存在吗?因为如果没有,当我尝试将某些内容保存到不存在的文件夹时,我会收到该错误:

> save(iris, file=file.path("results","foo.rda"))
Error in gzfile(file, "wb") : cannot open the connection
In addition: Warning message:
In gzfile(file, "wb") :
  cannot open compressed file 'results/foo.rda', probable reason 'No such file or directory'

如果我创建文件夹,那么它可以工作:

> dir.create("results")
> save(iris, file=file.path("results","foo.rda"))