It's obviously not something to advise in an ideal workflow but sometimes it can be useful.
Can it be done easily ?
Join Stack Overflow to learn, share knowledge, and build your career.
It's obviously not something to advise in an ideal workflow but sometimes it can be useful.
Can it be done easily ?
I made the following functions, it will put a temp file in your home folder and delete it when it's fetched by default :
shoot <- function(..., list = character(), rm = FALSE){
path <- file.path(path.expand("~"),"temp_object.RData")
save(..., list = list, file = path)
if(rm) rm(list = c(list,as.character(substitute(alist(...))[-1])),
envir = parent.frame())
invisible(NULL)
}
loot <- function(rm = TRUE){
path <- file.path(path.expand("~"),"temp_object.RData")
if(file.exists(path)){
load(path,envir = parent.frame())
if(rm) file.remove(path)
} else {
stop("nothing to loot!")
}
invisible(NULL)
}
test <- "abcd"
shoot(test)
rm(test)
loot() # in practice from another session
test
# [1] "abcd"
Useful in my case if one RStudio session has a bug and I can't plot, so I can send it to another.
With a simple change in the default path can be used in a network to easily pass data between colleagues for example.
Thanks to @MrFlick for suggestions
path.expand()
to more generally get a user's home directory. Also throw
and catch
are terms strongly associated with error handling. For clarity you might want to consider verbs with less "baggage".
– MrFlick
Oct 12 '18 at 15:38
tryCatch
in R
.
– Moody_Mudskipper
Oct 12 '18 at 15:41
sink
, if I could have found a good name...
– Moody_Mudskipper
Oct 15 '18 at 19:12