加载工作空间时出现“坏魔术数字”错误的原因及如何避免?

时间:2022-08-20 23:11:03

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

我试图加载我的R工作空间并收到这个错误:

Error: bad restore file magic number (file may be corrupted) -- no data loaded
In addition: Warning message:
file ‘WORKSPACE_Wedding_Weekend_September’ has magic number '#gets'
   Use of save versions prior to 2 is deprecated 

I'm not particularly interested in the technical details, but mostly in how I caused it and how I can prevent it in the future. Here's some notes on the situation:

我对技术细节不是特别感兴趣,但主要是我如何造成它,以及我如何在未来预防它。下面是一些关于这种情况的说明:

  1. I'm running R 2.15.1 on a MacBook Pro running Windows XP on a bootcamp partition.
  2. 我在一个bootcamp分区上运行Windows XP的MacBook Pro上运行r2.15.1。
  3. There is something obviously wrong this workspace file, since it weighs in at only ~80kb while all my others are usually >10,000
  4. 这个工作空间文件显然有问题,因为它的大小只有大约80kb,而我的其他文件通常是>10,000
  5. Over the weekend I was running an external modeling program in R and storing its output to different objects. I ran several iterations of the model over the course of several days, eg output_Saturday <- call_model()
  6. 上周末,我在R中运行了一个外部建模程序,并将其输出存储到不同的对象。我在几天内对模型进行了多次迭代,例如output_Saturday <- call_model()
  7. There is nothing special to the model output, its just a list with slots for betas, VC-matrices, model specification, etc.
  8. 模型输出没有什么特别之处,它只是一个列表,包含beta、vc - matrix、模型规范等的槽。

6 个解决方案

#1


64  

I got that error when I accidentally used load() instead of source() or readRDS().

当我不小心使用load()而不是source()或readRDS()时,我得到了这个错误。

#2


13  

Assuming your file is named "myfile.ext"

假设您的文件名为“myfile.ext”

If the file you're trying to load is not an R-script, for which you would use

如果您要加载的文件不是r脚本,您将使用它

source("myfile.ext")

you might try the readRDSfunction and assign it to a variable-name:

您可以尝试readRDSfunction,并将其分配给一个变量名:

my.data <- readRDS("myfile.ext")

#3


5  

The magic number comes from UNIX-type systems where the first few bytes of a file held a marker indicating the file type.

这个神奇的数字来自unix类型的系统,其中文件的前几个字节包含一个标记,指示文件类型。

This error indicates you are trying to load a non-valid file type into R. For some reason, R no longer recognizes this file as an R workspace file.

这个错误表明您正在尝试将一个无效的文件类型加载到R中。由于某些原因,R不再将这个文件识别为R工作区文件。

#4


4  

Install the readr package, then use library(readr).

安装readr包,然后使用库(readr)。

#5


1  

It also occurs when you try to load() an rds object instead of using

当您试图加载rds对象而不是使用它时,也会发生这种情况

object <- readRDS("object.rds")

#6


0  

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

如果您正在使用devtools,请尝试保存文件:

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.

内部If FALSE,将每个对象保存在data目录中的person .rda文件中。无论何时加载包,这些都是可用的。如果为真,则将所有对象存储在一个R/sysdata中。rda文件。这些对象仅在包中可用。

#1


64  

I got that error when I accidentally used load() instead of source() or readRDS().

当我不小心使用load()而不是source()或readRDS()时,我得到了这个错误。

#2


13  

Assuming your file is named "myfile.ext"

假设您的文件名为“myfile.ext”

If the file you're trying to load is not an R-script, for which you would use

如果您要加载的文件不是r脚本,您将使用它

source("myfile.ext")

you might try the readRDSfunction and assign it to a variable-name:

您可以尝试readRDSfunction,并将其分配给一个变量名:

my.data <- readRDS("myfile.ext")

#3


5  

The magic number comes from UNIX-type systems where the first few bytes of a file held a marker indicating the file type.

这个神奇的数字来自unix类型的系统,其中文件的前几个字节包含一个标记,指示文件类型。

This error indicates you are trying to load a non-valid file type into R. For some reason, R no longer recognizes this file as an R workspace file.

这个错误表明您正在尝试将一个无效的文件类型加载到R中。由于某些原因,R不再将这个文件识别为R工作区文件。

#4


4  

Install the readr package, then use library(readr).

安装readr包,然后使用库(readr)。

#5


1  

It also occurs when you try to load() an rds object instead of using

当您试图加载rds对象而不是使用它时,也会发生这种情况

object <- readRDS("object.rds")

#6


0  

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

如果您正在使用devtools,请尝试保存文件:

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.

内部If FALSE,将每个对象保存在data目录中的person .rda文件中。无论何时加载包,这些都是可用的。如果为真,则将所有对象存储在一个R/sysdata中。rda文件。这些对象仅在包中可用。