enable_debug_dump: Expression for dumping of objects from an evaluation stack

Description Usage Arguments Value See Also Examples

View source: R/Miscellaneous_Functions.R

Description

Create an expression for functions 'f' to set on.exit() such that all objects from the evaluation frame stack of function 'f' are collected and stored in a RData file

Usage

1
enable_debug_dump(dir_out = ".", file_tag = "debug")

Arguments

dir_out

A character string. The path to where the RData file is dumped.

file_tag

A character string. Will become final part of the RData file name.

Value

Expression.

See Also

set_options_warn_error with debug.dump.objects = TRUE

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
## Not run: 
f2 <- function(x, cause_error = FALSE) {
  print(match.call())
  print(environment())
  # Enable debug dumping
  on.exit(enable_debug_dump(file_tag = match.call()[[1]]), add = TRUE)
  # Add to 'on.exit'
  on.exit(print(paste("exit from", match.call()[[1]])), add = TRUE)

  res <- x + 100
  if (cause_error) stop("Create error and force debug dumping")

  # Remove debug dumping but not other 'on.exit' expressions before
  # returning without error
  oe <- sys.on.exit()
  oe <- remove_from_onexit_expression(oe, tag = "enable_debug_dump")
  do.call(on.exit, args = c(list(oe), add = FALSE))
  # Add to 'on.exit'
  on.exit(print(paste("exit2 from", match.call()[[1]])), add = TRUE)
  res
}

f1 <- function(x, cause_error) {
  print(paste(match.call()[[1]], x))
  print(environment())
  try(f2(x + 1, cause_error))
}

f1(0, cause_error = FALSE)
f1(0, cause_error = TRUE)
x <- new.env()
load("last.dump.f2.RData", envir = x)
ls.str(x)

# Clean up
unlink("last.dump.f2.RData")

## End(Not run)

Burke-Lauenroth-Lab/rSFSW2 documentation built on Aug. 14, 2020, 5:20 p.m.