r-lib / R6

Encapsulated object-oriented programming for R
https://R6.r-lib.org
Other
403 stars 56 forks source link

Setting breakpoints in methods #236

Open dmurdoch opened 2 years ago

dmurdoch commented 2 years ago

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.