r - 保存错误 : Error in gzfile(file, "wb") : 无法打开连接

标签 r save

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

gzfile(file, "wb") 中出现错误:无法打开连接 另外:警告消息: 在 gzfile(文件, "wb") 中: 无法打开压缩文件“results/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 初学者,我按照一本书来对我的硕士论文进行分析。

谢谢!

最佳答案

错误消息表明无法保存文件。它试图拯救什么?查看代码,它看起来像是试图保存在名为“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"))

关于r - 保存错误 : Error in gzfile(file, "wb") : 无法打开连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40240534/

相关文章:

r - 合并两个列不均匀的表并保留两个值

r - 从 SSIS 包执行 R 脚本

r - R 中的因式分解变量

r - 将图像设置为多边形的颜色

java - 如何写入文本文件并将其保存以供多次使用

list - 使用不同维度的数据框列表列表

唯一/保存/更新的Grails问题

python - 将 for 循环的输出保存到文件

c# - "Remember password"选项 [C#]

phpqrcode + 将缓存文件保存到亚马逊而不是服务器上的文件夹