R:不推荐使用 2 之前的保存版本

R: Use of save versions prior to 2 is deprecated

前段时间我使用保存功能将一些列表变量保存为文件

> str(ttr.varSD)
List of 4
 $ classifierLimits: Named num [1:5] 2 13 5 24 16
  ..- attr(*, "names")= chr [1:5] "sdClose-VS" "sdDiff-VS"...
 $ trainClassLabels: num [1:497] 4 2 3 4 2 3 2 4 1 4 ...
 $ testClassLabels : num [1:497] 4 2 2 4 4 4 4 4 4 4 ...
>
> save(ttr.varSD, file='ttr.varSD.RDS')

现在我想使用 load(file='ttr.varSD.RDS') 函数检索它们,但是 returns 这个错误。

>load(file='ttr.varSD.RDS')

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

This question 建议使用 read.table 函数,但我的数据不是 table。但我以任何方式对其进行了测试,它返回的显然不是我的完整数据:

> read.table('ttr.varSD.RDS')
          V1
1          X
2 sdClose-VS
3 sdClose-US
Warning messages:
1: In read.table("objects/ttr.varSD.RDS") :
  line 2 appears to contain embedded nulls
2: In read.table("objects/ttr.varSD.RDS") :
  line 3 appears to contain embedded nulls
3: In read.table("objects/ttr.varSD.RDS") :
  line 4 appears to contain embedded nulls
4: In read.table("objects/ttr.varSD.RDS") :
  incomplete final line found by readTableHeader on 'ttr.varSD.RDS'

是否有机会检索这些文件或所有文件都已损坏。为了了解我的工作环境,这可能很重要,我在 windows 7 上使用 R 版本 3.1.1 (2014-07-10) 和 RStudio,将我的所有工作与 google 驱动器同步并具有 git版本控制。

您可以使用函数 readRDS 来恢复存储在 .RDS 文件中的对象。在你的情况下:

readRDS('ttr.varSD.RDS')