Sets a break point that can be debugged like a restore point

Description

This function can be used as an alternative to browser(). When called inside a function, break.point stores all local objects and then does the following. i) If to global=FALSE (the default for break.point) starts the restore.point.browser for the local objects. ii) if to.global=TRUE copies the local objects to the global environment and stops execution.

Usage

1
2
3
4
break.point(name = "BREAK_POINT___",
  to.global = get.restore.point.options()$break.point.to.global,
  deep.copy = get.restore.point.options()$deep.copy, force = FALSE,
  dots = eval(substitute(list(...), env = parent.frame())))

Arguments

name

key under which the objects are stored. For restore points at the beginning of a function, I would suggest the name of that function.

to.global

if TRUE (default) objects are restored by simply copying them into the global environment. If FALSE a new environment will be created and the restore point browser will be invoked.

deep.copy

if TRUE try to make deep copies of objects that are by default copied by reference. Works so far for environments (recursivly). The function will search lists whether they contain reference objects, but for reasons of speed not yet in other containers. E.g. if an evironment is stored in a data.frame, only a shallow copy will be made. Setting deep.copy = FALSE (DEFAULT) may be useful if storing takes very long and variables that are copied by reference are not used or not modified.

force

store even if set.storing(FALSE) has been called

dots

by default a list of the ... argument of the function in whicht restore.point was called

Details

An alternative to break points are restore points. In the tutorial on GitHub, I provide some arguments how restore points can facilitate debugging compared to break points.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
## Not run: 
  library(restorepoint)
  set.restore.point.options(break.point.to.global = FALSE)
  # A function that shall swap the left and right part of a vector
  swap.in.vector = function(vec,swap.ind) {
    break.point()
    left  = vec[1:(swap.ind-1)]
    right = vec[swap.ind:nrow(vec)]
    c(right,left)
  }
  swap.in.vector(1:10,4)
  

## End(Not run)

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.