Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R:不推荐使用2之前的保存版本_R_List_Save_Load - Fatal编程技术网

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

R:不推荐使用2之前的保存版本,r,list,save,load,R,List,Save,Load,以前,我使用save函数将一些列表变量保存为文件 > 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 [

以前,我使用save函数将一些列表变量保存为文件

> 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')
函数检索它们,但它返回此错误

>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 
建议使用
read.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 drive同步,并具有git版本控制。

您可以使用function
readRDS
还原存储在.RDS文件中的对象。就你而言:

readRDS('ttr.varSD.RDS')

读RDS不走运吗?谢谢@Pascal你帮我省了不少时间。我想你应该回答这个问题,这样其他人可能会有同样的问题。我在尝试读取.rdata文件时出现了这个错误。使用
readRDS
而不是
load
就达到了目的。