I’m trying to understand some code I didn’t write (plot.gam in mgcv), and there’s a call to a plot() function with some strange parameters that I don’t recognize (e.g., “P”). I’d like to figure out which plot method is being dispatched on this call. findMethod() and similar functions don’t help (I think plot is S3). I tried the debug library, but that doesn’t let you “step into” a function call (and neither does the base debug functions).
Is there any way to monitor all function calls and their associated method dispatches in R? Or perhaps a function to which I can pass a string containing the actual function call (not just the signature) that will tell me what method gets dispatched?
In
plot.gam()we note thatplot()is called onx$smooth[[i]], which is an object of class:There is a
plot()method for class"mgcv.smooth"and it is this that is being used for the plot in the general case.?plot.gammentions that this is the default method used for most smooths, but there are specific methods for certain types of smooth supported bygam()(from Details section of?plot.gam:For some reason,
methods()is not finding these methods, but they do exist:This may be related to a bug in
methods()that meantplot.functionwas not shown in the list and my current R might not incorporate that fix. This method should be shown normally, and the general advice in such situations would be to identify the class of object (as I showed above) and then usemethods()and similar functions (e.g.showMethods()) to identify if specific methods available for the class(es) of the object returned.