In R, how do you know which method is dispatched for a particular function call?

I am trying to understand code that I did not write (plot.gam in mgcv), and there is a call to the plot () function with some strange parameters that I do not recognize (for example, "P")). I would like to find out which chart method is sent to this call. findMethod () and similar functions do not help (I think it is S3). I tried the debug library, but this does not allow you to “enter” the function call (and also does not perform the functions of basic debugging).

Is there a way to keep track of all function calls and associated method dispatches in R? Or perhaps a function with which I can pass a string containing the actual function call (and not just the signature) that will tell me which method is sent?

+5
source share
3 answers

In plot.gam()note that plot()is called on x$smooth[[i]], which is an object of the class:

class(x$smooth[[i]])
[1] "tprs.smooth" "mgcv.smooth"

There is a method plot()for the class "mgcv.smooth", and this is what is used for the graph in the general case. ?plot.gammentions that this is the default method used for most smoothnesses, but there are specific methods for certain types of fins supported gam()(from the details section ?plot.gam:

For smooth terms ‘plot.gam’ actually calls plot method functions
depending on the class of the smooth. Currently random effect and
Markov random field smooths have special methods, the rest use the
defaults described below.

For some reason, methods()does not find these methods, but they exist:

> mgcv:::plot.mgcv.smooth
function (x, P = NULL, data = NULL, label = "", se1.mult = 1, 
    se2.mult = 2, partial.resids = FALSE, rug = TRUE, se = TRUE, 
    scale = -1, n = 100, n2 = 40, pers = FALSE, theta = 30, phi = 30, 
    jit = FALSE, xlab = NULL, ylab = NULL, main = NULL, ylim = NULL, 
    xlim = NULL, too.far = 0.1, shade = FALSE, shade.col = "gray80", 
    shift = 0, trans = I, by.resids = FALSE, scheme = NULL, ...) 
{
....

​​ methods(), , plot.function , R . , , ( ), methods() (, showMethods()), , .

+5

S3 methods("plot") , . S3 . plot.gam, , plot(x$smooth[[i]]), , x$smooth[[i]] ( x - gam), , plot.

, .

+2

. , trace().

0

All Articles