[ESS] suggestion: eldoc support for S4 methods

Vitalie Spinu spinuvit at gmail.com
Sat May 18 15:45:03 CEST 2013

It does work for S3 methods, all arguments sown after || are not from

ESS heavily relies on internal R completion. I asked Deepayan Sarkar
(the author of R's completion) several years ago if it would be possible
to dispatch on first argument, and he ruled it out as inefficient and
not worth it in terms of the benefits it brings.

I tend to agree with that, because S4 methods usually use the same
arguments as the generic so it's really not a big deal. I am a heavy
user of S4 and with current eldoc I almost never have a need for this

I also don't yet see a convenient user workflow. When you say "on
demand" do you mean a reserved key for eldoc invocation with evaluation
of arguments? That might be a good idea, any suggestions for a key


 >> Michael Lawrence <lawrence.michael at gene.com>
 >> on Sat, 18 May 2013 06:19:34 -0700 wrote:

 > I really like the new eldoc that is turned on in 13.04, and it would be
 > cool to make it work on S4 methods. Right now, it accesses only the
 > generic, which is often insufficient, because S4 methods will add arguments
 > as allowed by the presence of "..." in the generic formals.

 > Having no idea of how this works inside ESS, I thought that if you could
 > somehow get the text of the call, you could use selectMethod() to find the
 > actual method. I threw together the function below just for fun. It takes a
 > string representation of an R call, parses it, evaluates the arguments,
 > matches them to elements of the generic signature, and resolves the method.
 > It even handles the ".local" delegation that happens when methods add
 > formal arguments as mentioned. The evaluation of the arguments might be
 > expensive, so this should be on-demand only.

 > parseToSelectMethod <- function(expr) {
 >     call <- parse(text = expr)[[1]]
 >     generic <- match.fun(call[[1]])
 >     matched.call <- match.call(generic, call)
 >     args <- lapply(as.list(matched.call[-1]), eval, parent.frame())
 >     classes <- vapply(args, class, character(1))
 >     classes.sig <- classes[generic at signature]
 >     method <- selectMethod(generic, classes.sig)
 >     method.body <- body(method)[[2]]
 >     has.local <- identical(quote(`<-`(.local)), method.body[1:2])
 >     if (has.local) {
 >         method <- method.body[[3]]
 >     }
 >     method
 > }

 > Hope that helps some,
 > Michael

 > 	[[alternative HTML version deleted]]

 > ______________________________________________
 > ESS-help at r-project.org mailing list
 > https://stat.ethz.ch/mailman/listinfo/ess-help

More information about the ESS-help mailing list