R6 icon indicating copy to clipboard operation
R6 copied to clipboard

Setting breakpoints in methods

Open dmurdoch opened this issue 2 years ago • 0 comments

The debugging vignette says RStudio debugging doesn't work with R6 methods. A step towards this would be to allow breakpoints to be set in methods by location, similar to the utils::setBreakpoint function.

I've written a simple version of this, which appears as a generator method: https://github.com/dmurdoch/R6/blob/b233e0a2f3f6d922df753416729992000d1f5f73/R/generator_funs.R#L105 .

The function would also work on an instance, but I haven't added it: I'm not sure all users would want a new setBreakpoint method to show up. Alternatively, the standard function can be used on instance as

setBreakpoint("filename#line", envir = instance)

though I don't think this will see private methods.

In order to allow breakpoints to be set in RStudio, it would also need to identify ranges of code that are within the R6Class definition. This could be tricky, because function definitions might not appear within the call, e.g.

fn <- function(x) print(x)

R6Class(public = list(fn = fn))

However, I guess there would be some workaround.

I'd be happy to put together a PR for this if there's interest.

dmurdoch avatar Nov 10 '21 13:11 dmurdoch