For information on using this system, please visit this page.

Bug 17116 - Wishlist: include .GlobalEnv in dump of dump.frames()
Summary: Wishlist: include .GlobalEnv in dump of dump.frames()
Status: CLOSED FIXED
Alias: None
Product: R
Classification: Unclassified
Component: Wishlist (show other bugs)
Version: R-devel (trunk)
Hardware: All All
: P5 enhancement
Assignee: R-core
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-07-11 13:00 UTC by Andreas Kersting
Modified: 2016-08-16 15:40 UTC (History)
1 user (show)

See Also:


Attachments
patch for dump.frames() with option to include .GlobalEnv (1.15 KB, patch)
2016-07-11 13:00 UTC, Andreas Kersting
Details | Diff
dump.frames using as.environment(as.list(.GlobalEnv, all.names = TRUE)) (1.12 KB, text/x-r-source)
2016-08-12 12:51 UTC, Andreas Kersting
Details
dump.frames using only .GlobalEnv (1.05 KB, text/x-r-source)
2016-08-12 12:51 UTC, Andreas Kersting
Details
check last.dump for correct content (242 bytes, text/x-r-source)
2016-08-12 12:52 UTC, Andreas Kersting
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Andreas Kersting 2016-07-11 13:00:52 UTC
Created attachment 2124 [details]
patch for dump.frames() with option to include .GlobalEnv

dump.frames() should (optionally) include the global environment in the returned list of environments. This could greatly ease the debugging after a script running in a non-interactive R session with options(error = quote({dump.frames(to.file = TRUE); q(status = 1)})) failed with a non-catastrophic error.

I attached a patch which implements the proposed functionality.
Comment 1 Martin Maechler 2016-08-10 15:49:07 UTC
(In reply to Andreas Kersting from comment #0)
> Created attachment 2124 [details]
> patch for dump.frames() with option to include .GlobalEnv
> 
> dump.frames() should (optionally) include the global environment in the
> returned list of environments. This could greatly ease the debugging after a
> script running in a non-interactive R session with options(error =
> quote({dump.frames(to.file = TRUE); q(status = 1)})) failed with a
> non-catastrophic error.
> 
> I attached a patch which implements the proposed functionality.

Thank you.  Your wish seems reasonable to me; the patch as well,
apart from

     as.environment(as.list(.GlobalEnv, all.names = TRUE)) 

Can you show a case where the above is *different* from  .GlobalEnv  ?
Comment 2 Andreas Kersting 2016-08-12 12:51:13 UTC
Created attachment 2136 [details]
dump.frames using as.environment(as.list(.GlobalEnv, all.names = TRUE))
Comment 3 Andreas Kersting 2016-08-12 12:51:52 UTC
Created attachment 2137 [details]
dump.frames using only .GlobalEnv
Comment 4 Andreas Kersting 2016-08-12 12:52:21 UTC
Created attachment 2138 [details]
check last.dump for correct content
Comment 5 Andreas Kersting 2016-08-12 12:52:56 UTC
(In reply to Martin Maechler from comment #1)
> (In reply to Andreas Kersting from comment #0)
> > Created attachment 2124 [details]
> > patch for dump.frames() with option to include .GlobalEnv
> > 
> > dump.frames() should (optionally) include the global environment in the
> > returned list of environments. This could greatly ease the debugging after
> a
> > script running in a non-interactive R session with options(error =
> > quote({dump.frames(to.file = TRUE); q(status = 1)})) failed with a
> > non-catastrophic error.
> > 
> > I attached a patch which implements the proposed functionality.
> 
> Thank you.  Your wish seems reasonable to me; the patch as well,
> apart from
> 
>      as.environment(as.list(.GlobalEnv, all.names = TRUE)) 
> 
> Can you show a case where the above is *different* from  .GlobalEnv  ?


Please consider (see also attached files):

andreas@t410debian:~$ Rscript dump.frames_with_as.list.R 

Creating 'test_object' in the global environment.
Done. Throwing a simple error now:
Fehler: A simple error!
andreas@t410debian:~$ Rscript check_last.dump.R 

Does 'test_object' exist in last.dump$.GlobalEnv?
[1] TRUE

What's the content of the environment last.dump$.GlobalEnv?
[1] "dump.frames" "test_object"

andreas@t410debian:~$ Rscript dump.frames_without_as.list.R

Creating 'test_object' in the global environment.
Done. Throwing a simple error now:
Fehler: A simple error!
andreas@t410debian:~$ Rscript check_last.dump.R 

Does 'test_object' exist in last.dump$.GlobalEnv?
[1] FALSE

What's the content of the environment last.dump$.GlobalEnv?
[1] "last.dump"


So when we do not use

     as.environment(as.list(.GlobalEnv, all.names = TRUE))

but only

     .GlobalEnv

last.dump$.GlobalEnv rather refers to the *current* global environment and not to that of the R session where dump.frames() was called.
Comment 6 Martin Maechler 2016-08-12 20:08:26 UTC
Thank you for providing so much evidence.

Of course you are right and it is necessary to make a "deep copy" of an environment...  and your   as.environment(as.list(ENV, all.names=TRUE))  
is a workaround for a missing   cp_env(EEE)   function.
Comment 7 Martin Maechler 2016-08-16 15:40:56 UTC
I have committed a version of your patch to R-devel (only), svn -c71102