I started with a Microsoft R Open 3.4.4 installation on my windows 10 desktop. I then installed R version 3.6.1 side-by-side. They each use only their own site library (no cross-over through a common user level package folder, just the one under the installation folder) with their own packages. However, when I run the 3.4.4 RGui I get the above error. I have even uninstalled the 3.6.1 version and still get the error.
Is there some sort of default workspace file on my machine that is loaded at start-up that has been updated that I can save down using the 3.4.4 version to prevent me getting this error, or is there some other way of enforcing complete isolation of R environments as I have a genuine requirement to have 3.4.4 and cannot just upgrade to a later version?
Check out help(saveRDS).
I think you will need to specify the version= to ensure cross compatibility. A change from default version=2 to version=3 occurred with R-3.5.0
It sounds like you are allowing R/Rstudio to save a .Rdata file at the end of a session under one R version, and then R is trying to load that .Rdata file automatically when you start a session with a different R version.
One solution to prevent this: first turn off automatic saving of .Rdata files in RStudio>Tools>Global Options>General>Basic.
Then, at the end of your R script file(s) add a manual creation of the .Rdata file using something like this:
my_data <- data.frame(aa=c(1:10), bb= letters[1:10])
# Save one object (or can use a list of objects)
saveRDS(my_data, file=".Rdata", version=2)
# Or save everything
save.image(version=2)
This output file should then be readable in other versions of R.
HTH
This was using RGui.exe (i.e. RStudio not involved). If I perform a list.files('.') when starting up then I see no Rdata file which is why I'm left wondering what it is up to and whether it is loading some sort of global configuration file which may have been affected.
Is there somewhere else it will load .Rdata files from other than the working folder?
Sorry, I missed that you are working with Rgui.
Also the image files are .RData (not .Rdata).
AFAIK they are only loaded from the working directory.
In order to see every file in a directory you need to run
list.files(all.files=TRUE)
# or
dir(all.files=TRUE)
This will show whether any .RData files exist.
The save.image() function should then work.
To prevent automatic creation of .RData you will need quit(save="no")
at the end of each session, or redefine the quit() function:
q <- function (save="no", ...) {
quit(save=save, ...)
}
and have this stored in your .Rprofile file, see help("startup").
HTH
Hi @mt96,
Not sure if my previous suggestion solved your .RData problem?
Another way to tackle this is to make use of a .Last() function, located in either your .Rprofile or Rprofile.site file, which is the last thing executed before R closes.
See this link for some background https://www.statmethods.net/interface/customizing.html
In your case this should work, in combination with the redefined quit() (see above):
.Last <- function(){
save.image(version=2)
cat("\n.RData file in version=2 format has been saved\n")
invisible(readline(prompt="Press [enter] to quit"))
}
HTH