My compute cluster recently updated to R version R 3.6.0 and deleted the old versions of R. I had been running my project in R 3.4.0. I decided this would be fine, ran some code, and saved the output during my R 3.6.0 session as:
saveRDS(output, output.path)
This file was then transferred to a different computer where interactive R use takes place. This computer runs R/3.4.0
, and updating the version of R is not an option. When I go to open the above file, I get the following error:
readRDS(output.path)
Error in readRDS(output.path) : cannot read workspace version 3 written by R 3.6.0; need R 3.5.0 or newer
This is a bummer. I am not the system administrator on either of these computers, so I can't just synchronize the versions. This is my question:
Is there a way to write a file using saveRDS()
in R 3.6.0 such that it would be backward compatible in an R 3.4.0 environment?
Expanding on my comment with a demo:
$ Rscript --version | head -1
R scripting front-end version 3.6.0 (2019-04-26)
$ Rscript -e 'saveRDS(1:10, file="foo.rds")'
$
$ docker run --rm -ti r-base:3.4.0 Rscript --version | head -1
R scripting front-end version 3.4.0 (2017-04-21)
$ docker run --rm -ti -v ${PWD}:/work -w /work r-base:3.4.0 Rscript -e 'print(readRDS("foo.rds"))'
Error in readRDS("foo.rds") :
cannot read workspace version 3 written by R 3.6.0; need R 3.5.0 or newer
Calls: print -> readRDS
Execution halted
$
$ Rscript -e 'saveRDS(1:10, file="foo.rds", version=2)'
$ docker run --rm -ti -v ${PWD}:/work -w /work r-base:3.4.0 Rscript -e 'print(readRDS("foo.rds"))'
[1] 1 2 3 4 5 6 7 8 9 10
$
I use my normal R version which I show to be 3.6.0, and I then launch R 3.4.0 via Rocker, also showing its version.
As expected, it first fails -- and once the data is resaved with version=2
it works as is should.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With