Last night, after some exhausting debugging, I finished a new function that ran little over 5 hours and was to save into an object.
myResult <- myComputation(myArgument)
Something like this. Unfortunately, the function was still in debug mode, so after finishing without errors myResult remains nonexistent.
Is there a way to save/recover objects from browsing/debugging mode?
Yes, it is possible.
If you have an existing variable in the global environment you can use the variableName<<-
operator. Alternative use the assign(variableNameAsString, ObjectToSave, globalenv())
where variableNameAsString
should be replaced by the name you want to save your output under, and ObjectToSave
is the object to save. This will save your object after the debug session is quit.
Very quick example:
x <- 3
#dummy function that someone did not remember to return stuff from
xfunc <- function(x){
x <- x * 3
assign("cookieMonster", x, globalenv())
browser()
cat("hello world")
}
x2 <- xfunc(x)
x2
[1] NULL
cookieMonster
[1] 9