Combining or merging workspaces in R and general workspace management

project, r, workspace

Solution

I think one needs to build ones own function here doing the following:

loading the workspaces one after one, using:

load()

renaming each element of the workspace to prevent overriding when loading another workspace or putting it into a list

checking the timestamp of the workspaces with:

file.info()

and keeping only the newest objects, which are then to be saved in some up-to-date workspace

Example:

for(i in 1:10){
    dummy <- rnorm(1)
    Sys.sleep(1.3)
    save(dummy,file=paste("test",i,".Rdata",sep=""))
}

DUMMY <- list()
timestamps <- NULL

for(i in 1:10){
    filename <- paste("test",i,".Rdata",sep="")
    load(filename)
    DUMMY[[i]] <- dummy
    timestamps[i] <- file.info(filename)$mtime
}

uptodate <- unlist(timestamps)==max(unlist(timestamps))
dummy <- unlist(DUMMY[uptodate])
save(dummy,file="uptodate.Rdata")

Problem

I often find myself transferring workspaces to different scratch drives etc when one computing system is down/busy, or, I want to run two long-winded packages simultaneously to save time and loading the same workspace twice in different places. Because of this, I'd really love a way to see the different objects between workspaces and a way to combine them, adding only the new, changed or updated workspace objects to a similar workspace. This would be extremely useful for me. So far I am relying on manual note-taking and getting befuddled with my scribbles two weeks down the line. I really just want to learn so good working practices and habits that make this sort of this easier. Generally I would really like to learn more about workspace management and how experienced users keep workspaces for long, ongoing projects comprehensive and tidy. I often use Rstudio but working remotely or using our HPC system it can be a bit laggy and clunky so I tend to use command line and interactive sessions. I think maybe making lists of objects might be the key, but I'd like to be able to annotate things more easily, maybe with the data and parameters used to make the object etc. Thanks.

Original source

Related problems