Reputation: 155
I have a 3d array in R which takes quite some time to calculate.
I am looking for the easiest way to store this array so it can be read back into R quickly and in an array format.
Can anyone explain how to do this?
I have tried using
saveRDS(x_out, file="x_out.Rda")
x_out1 <- load(file="x_out.Rda")
but this leads to an error.
Error: bad restore file magic number (file may be corrupted) -- no data loaded
In addition: Warning message:
file ‘x_out.Rda’ has magic number 'X'
Use of save versions prior to 2 is deprecated
Any suggestions?
Upvotes: 4
Views: 8139
Reputation: 11
I am saving and loading 3D numeric arrays just with save()
and load()
commands:
save(x, file="something.rda")
load("something.rda")
Upvotes: 1
Reputation: 193587
Bad magic file type errors are usually because you're trying to use the wrong function to read a particular file type.
The inverse of saveRDS
is readRDS
, not load
.
Demo:
saveRDS(c(1:3), "test.rds")
x <- load("test.rds")
# 'Error: bad restore file magic number (file may be corrupted) -- no data loaded
# In addition: Warning message:
# file ‘test.rds’ has magic number 'X'
# Use of save versions prior to 2 is deprecated
x <- readRDS("test.rds")
x
# [1] 1 2 3
Upvotes: 7