error saving: Error in gzfile(file, “wb”) : cannot open the connection

扶醉桌前 提交于 2021-01-29 04:33:45

问题


I am trying to run a LDA topic analysis on Rstudio 3.3.0. I am at the following step but keep getting the error:

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

There is a problem while saving.

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))
  }
}

There is enough workspace on my computer, and I tried to restart r several times and yes I looked at the other questions but none of the solutions seem to work.

> 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    

I am a beginner in R and I follow a book to conduct the analysis for my master thesis.

Thanks!


回答1:


The error message says it can't save the file. What is it trying to save? Looking at the code it looks like its trying to save in a folder called "results". Does this folder exist? Because if it doesn't, I get that error when I try and save something to a non-existent folder:

> 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'

If I create the folder then it works:

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


来源:https://stackoverflow.com/questions/40240534/error-saving-error-in-gzfilefile-wb-cannot-open-the-connection

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!