We implement methods in S4 as anonymous functions which are used within the setMethod call to define a method. Because of this, the R debugger does not have access to the source code for that implementation, and debugging is much harder. In addition, IDE tools like RStudio have function lists that are less than useful (just lists of undifferentiated anonymous functions). To fix this, I propose refactoring our code to eliminate use of these anonymous functions by creating non-exported private functions in each class. For example, our current code has methods defined like:
The new non-exported getSize_ function now is visible to debugging code and IDEs. In addition, note that I now removed the anonymous block wrapping the standardGeneric call, as recommended by Hadley Wickham in Advanced R.
I've checked in an example of how this works for the DataPackage class in the feature-debuggable-S4 branch. We would need to implement this for all o the classes, which will take a bit of time but is fairly rote if done without other functional changes.
@gothub @amoeba Comments and thoughts appreciated.
We implement methods in S4 as anonymous functions which are used within the
setMethod
call to define a method. Because of this, the R debugger does not have access to the source code for that implementation, and debugging is much harder. In addition, IDE tools like RStudio have function lists that are less than useful (just lists of undifferentiated anonymous functions). To fix this, I propose refactoring our code to eliminate use of these anonymous functions by creating non-exported private functions in each class. For example, our current code has methods defined like:and I propose we change that to:
The new non-exported
getSize_
function now is visible to debugging code and IDEs. In addition, note that I now removed the anonymous block wrapping thestandardGeneric
call, as recommended by Hadley Wickham in Advanced R.I've checked in an example of how this works for the
DataPackage
class in thefeature-debuggable-S4
branch. We would need to implement this for all o the classes, which will take a bit of time but is fairly rote if done without other functional changes.@gothub @amoeba Comments and thoughts appreciated.