error message: bad restore file magic number (file may be corrupted) -- no data loaded

Dear all,

I searched in this and in many other forums about an error (explained below) that I am getting. The answers could not help.

I saved Rdata file by replacing an already existing file (both the old and new files had a memory of 8GB)

The newly saved file now shows just 30 kb memory.

I tried to load the new file:

load("/media/physioch/data/Combined/allcx/subsets/ecallcx subsets.RData")

I get following error

Error in load("/media/physioch/data/Combined/allcx/subsets/ecallcx subsets.RData") :
bad restore file magic number (file may be corrupted) -- no data loaded
In addition: Warning message:
file ‘ecallcx subsets.RData’ has magic number 'Featu'
Use of save versions prior to 2 is deprecated

I looked into some forums and understood that this could be a problem of R version.
While saving the file, I did not do anything different: I simply used save button in the Environment space and replaced the already existing file.
I tried using ReadRDS, readr but no help.

How can I restore my file?
other details:
platform x86_64-pc-linux-gnu
arch x86_64
os linux-gnu
system x86_64, linux-gnu
major 3
minor 6.1
year 2019
month 07
day 05
svn rev 76782
language R
version.string R version 3.6.1 (2019-07-05)
nickname Action of the Toes

1 Like

It's probably not an RData file.

Likely it's a file that got misnamed with the wrong extension. The magic number should start with "RDA2" or something like that. File format magic numbers are traditionally the first bytes of a file. Seeing something that looks like a fragment of a column name leads one to believe that it's not an RData file, some plain text that begins with "Featu"

Could be a CSV or TSV file

Is the first column of the data named "Feature"? It might be an issue of a someone using write() instead of save() to serialize a data frame to disk. If that is the case, read.csv() or read.delim() would be appropriate.

Could be RDS file

Try readRDS() if the above doesn't work. It doesn't seem like it should be an ascii rds file, but worth a try if it's not csv or tsv.


..Thank you Colin Gross.

You identified the problem correctly. I could access the file in console with read.csv

read.csv("/media/physioch/data/Combined/allcx/subsets/ecallcx subsets.RData")

The first column was indeed "feature"

The file can also be accessed in console using read.delim

read.delim("/media/physioch/data/Combined/allcx/subsets/ecallcx subsets.RData")

This gives list of all commands that I previously ran on data.

I don't quite understand what caused this.. (you wrote " It might be an issue of a someone using write() instead of save() to serialize a data frame to disk" I have to read to understand this) but I saved the files like this (save button in 'environment' space) before without any problem.

My file contained a lot of data (objects, data frames etc). Please guide me- how can I restore the file.

Best wishes,

Write() vs Save()

I expect someone did something like the following.

write.csv(my_data_frame, file="/path/to/my/file.RData")

instead of doing

save(my_data_frame, file="/path/to/my/file.RData")


The save workspace button of Rstudio should have created an RData file. If you're seeing that file is a csv file, then it was likely overwritten somehow. Unfortunately, that means the file that the workspace was saved to is no longer there. This could have by passing the .RData path to a subsequent call to write.csv() or perhaps when copying or moving files around from whatever file manager on the system is.


If the file was indeed overwritten, recovering an overwritten file may be possible, but seems unlikly. It will dependent on your operating system and file system configuration, and is beyond the scope of this forum. I would not expect that the original RData file is recoverable.

1 Like

Thank you Colin Gross. I realized the problem now.

I had pressed save button when history tab was active instead of pressing Save button when Environment tab should be on.

savehistory(/media/physioch/data/Combined/allcx/subsets/ecallcx subsets.RData)
instead of
save.image("/media/physioch/data/Combined/allcx/subsets/ecallcx subsets.RData")

The file is definitely overwritten but fortunately I have all the commands. I will re-run those on the raw data to get back my file. A lesson learnt!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.