【问题标题】:error saving: Error in gzfile(file, "wb") : cannot open the connection错误保存:gzfile 中的错误(文件,“wb”):无法打开连接
【发布时间】:2017-03-07 12:52:11
【问题描述】:

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

gzfile(file, "wb") 中的错误:无法打开连接 另外:警告信息: 在 gzfile(file, "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 的初学者,我按照一本书为我的硕士论文进行分析。

谢谢!

【问题讨论】:

    标签: r save


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-18
      • 2018-08-11
      • 1970-01-01
      相关资源
      最近更新 更多