The cause of “bad magic number” error when loading a workspace and how to avoid it?

后端 未结 9 1229
自闭症患者
自闭症患者 2020-11-29 05:54

I tried to load my R workspace and received this error:

Error: bad restore file magic number (file may be corrupted) -- no data loaded
In addition: Warning m         


        
相关标签:
9条回答
  • 2020-11-29 06:22

    I got the error when building an R package (using roxygen2)

    The cause in my case was that I had saved data/mydata.RData with saveRDS() rather than save(). E.g. save(iris, file="data/iris.RData")

    This fixed the issue for me. I found this info here

    Also note that with save() / load() the object is loaded in with the same name it is initially saved with (i.e you can't rename it until it's already loaded into the R environment under the name it had when you initially saved it).

    0 讨论(0)
  • 2020-11-29 06:26

    I had this problem when I saved the Rdata file in an older version of R and then I tried to open in a new one. I solved by updating my R version to the newest.

    0 讨论(0)
  • 2020-11-29 06:27

    If you are working with devtools try to save the files with:

    devtools::use_data(x, internal = TRUE)
    

    Then, delete all files saved previously.

    From doc:

    internal If FALSE, saves each object in individual .rda files in the data directory. These are available whenever the package is loaded. If TRUE, stores all objects in a single R/sysdata.rda file. These objects are only available within the package.

    0 讨论(0)
提交回复
热议问题