saveRDS() and readRDS() Why? [solved, pretty much anyway)
On 2018-11-12 22:49, peter dalgaard wrote:
Er, where, what, how? I can't reproduce that, at least not on 3.5.1 on MacOS:
x <- airquality saveRDS(x, file = "x.rds") x <- NULL x <- readRDS(file = "x.rds") x
Ozone Solar.R Wind Temp Month Day 1 41 190 7.4 67 5 1 2 36 118 8.0 72 5 2 3 12 149 12.6 74 5 3 ... Looks fine to me.
It seems to work fine using the same installation to read as used for the save. But it's a different story if the save was done on a Windows installation and read on a Linux installation. ## On Windows 3.4.2
x <- airquality saveRDS(x, file = "x.rds") saveRDS(x, file = "y.rds")
Files x.rds and y.rds are identical in size but utterly different in content. ## On Linux 3.5.1
x <- readRDS(file = "x.rds")
Error in readRDS(file = "x.rds") : error reading from connection
x <- readRDS(file = "y.rds") head(x)
Ozone Solar.R Wind Temp Month Day 1 41 190 7.4 67 5 1 2 36 118 8.0 72 5 2 3 12 149 12.6 74 5 3 4 18 313 11.5 62 5 4 5 NA NA 14.3 56 5 5 6 28 NA 14.9 66 5 6 It might just be the age of the Windows installation. I don't have much use for Windows, so I haven't had much inclination to install a newer version. YMMV
? -pd
On 12 Nov 2018, at 08:28 , Patrick Connolly <p_connolly at slingshot.co.nz> wrote: The solution was very simple. Don't use the same name for the rds file as used for the R object, viz a vie: saveRDS(x, file = "x.rds") and x <- readRDS(file = "x.rds") will not work; however saveRDS(x, file = "y.rds") and x <- readRDS(file = "y.rds") will work. An undocumented feature? Thanks to all who contributed.
-- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Office: A 4.23 Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com