11

Some times ago I saved some list variables as files using save function

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

Now I want to retrieve them using load(file='ttr.varSD.RDS') function but it returns this error.

>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 suggests using read.table function but my data is not a table. But I tested it any way and it returned this which is clearly not my complete data:

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

Is there any chance to retrieve these files or all of them has been corrupted. To know my working environment , as it might matter, I am using R version 3.1.1 (2014-07-10) with RStudio on windows 7,synchronizing all my work with google drive and have git version control.

Community
  • 1
  • 1
Polla A. Fattah
  • 801
  • 2
  • 11
  • 32

1 Answers1

11

You can use function readRDS to restore an object stored in a .RDS file. In your case:

readRDS('ttr.varSD.RDS')