2

I have been trying to save my R environment to load in later sessions (my environment has about 12 data frames).

save.image(file = 'tests.RData')

if I look in my directory, my file looks like data has been saved since the .RData file is about 40MB in size.

Now when I try to load the file in the directory...

load('test.RData')

I get this error:

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

I tried looking at previous issues with this, and the only advice was to try load() and source(). However, I believe load() is for .rda/.RData files.

Is there anyway to save my environment and load it properly? What is causing my issue exactly?

joran
  • 157,274
  • 30
  • 404
  • 439
user7180132
  • 271
  • 4
  • 14
  • 1
    input the full path to the load function – Crt Mar 09 '17 at 22:29
  • Possible duplicate of [What could cause a "bad magic number" error when loading an R workspace and how to avoid it?](http://stackoverflow.com/questions/12463583/what-could-cause-a-bad-magic-number-error-when-loading-an-r-workspace-and-how) – Crt Mar 09 '17 at 22:37
  • Putting the full path into the load function did not work...if I dir() the directory, I see the .RData file in there as well. – user7180132 Mar 09 '17 at 22:52
  • The other question that was asked unfortunately does not work for me....I am using the load() function for .RData files and am still getting an error message – user7180132 Mar 09 '17 at 22:53
  • have you tried ```source``` instead – Crt Mar 09 '17 at 22:54
  • I get this error: > source('tests.RData') Error in source("tests.RData") : tests.RData:2:1: unexpected input 1: 2: ^ – user7180132 Mar 09 '17 at 22:58
  • `source` is for reading and executing R code, not loading data. – neilfws Mar 09 '17 at 23:01
  • ^^ That's why I'm curious as why I am still getting an error, as everyone seems to assume I'm mixing up load() and source(). My guess would be that there was an issue with the save.image() function...is that the only way to save an environment? – user7180132 Mar 09 '17 at 23:43
  • It's not clear if you're entering the file name correctly. What does `list.files()` say? Is this file present? – Roman Luštrik Mar 10 '17 at 15:02
  • After I enter the command save.image(file = 'tests.RData') and then hit list.files(), I see the 'tests.RData' present – user7180132 Mar 10 '17 at 15:51
  • for some reason sometimes when I save the extension as '.RData', the file is present but is 0kb in size. Everytime when I save the extension as '.rda', the file is present and is about 40MB in size but gives me the same error when I try to load it. Could it by that there is something weird going on when I try to save a binary file? – user7180132 Mar 10 '17 at 15:55

0 Answers0