Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug S4 class in RStudio

Here is my S4 class, which is saved in separate file and currently open in RStudio:

setClass(
  Class = 'some_cls', 
  slots = c(some_slot = 'numeric'),
)


setGeneric("some_method", function(self)
  standardGeneric("some_method"))
setMethod("some_method", 
          signature(self = "some_cls"), 
          function(self) {
            self@some_slot <- 5
            self
          }
)

In another file I execute:

some_obj <- new('some_cls')
some_obj <- some_method(some_obj)

I tried to debug some_method as I would normally do in RStudio. I put dot next to line self@some_slot <- 5, in I RStudio I clicked Source in top right corner, but code execution did not stop at breakpoint. What am I doing wrong?

like image 277
user1700890 Avatar asked Oct 23 '25 22:10

user1700890


1 Answers

This looks like a bug in RStudio; you might want to report it to them. The underlying infrastructure in R has no problem handling a situation like yours.

For example, if the first file is called test.R, and you want the breakpoint on line 12, just run

setBreakpoint("test.R#12")

and execution will break when you get there.

like image 177
user2554330 Avatar answered Oct 25 '25 12:10

user2554330