From vogranovich at jumptrading.com  Mon Sep 14 19:58:11 2009
From: vogranovich at jumptrading.com (Vadim Ogranovich)
Date: Mon, 14 Sep 2009 12:58:11 -0500
Subject: [Rd] Save all objects in all environment stack
Message-ID: <22D850BC39A25742977325ADDE208E770271F72105@chiexchange02.w2k.jumptrading.com>

Dear R Developers,

I am writing a function that would save all objects in all environments 'visible' from the point where the function is called (very much like save.image, but kind of saving the entire stack).

I figured that the call
lapply (seq(0, sys.nframe()), function(i) ls(sys.frame(i), all.names=T))
will list all such objects.

However not all of them seem to be visible, see a session transcript below

## create a simple function with a 'breakpoint'
> f <- function(x) { browser() }
## call f in lapply inside an anonymous function defined on the fly
> (function(d) lapply('a', f))('d')
Called from: FUN("a"[[1L]], ...)
## Examine all frames
Browse[1]> lapply(seq(0, sys.nframe()), function(i) ls(sys.frame(i), all.names=T))
[[1]]
[1] "f"

[[2]]
[1] "d"

[[3]]
[1] "..." "FUN" "X"

[[4]]
[1] "x"

## try to get d, which is in the second entry on the list
Browse[1]> d
Error: object 'd' not found

Why 'd' is not found?

Did anyone try to write a function that, loosely speaking, saves the entire stack?

Thanks,
Vadim

Note: This email is for the confidential use of the named addressee(s) only and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you are hereby notified that any review, dissemination or copying of this email is strictly prohibited, and to please notify the sender immediately and destroy this email and any attachments.  Email transmission cannot be guaranteed to be secure or error-free.  Jump Trading, therefore, does not make any guarantees as to the completeness or accuracy of this email or any attachments.  This email is for informational purposes only and does not constitute a recommendation, offer, request or solicitation of any kind to buy, sell, subscribe, redeem or perform any type of transaction of a financial product.



[Rd] Save all objects in all environment stack
Vadim Ogranovich