Bug 15680

Summary: ?generic(arg) broken for many methods
Product: R Reporter: Michael Lawrence <michafla>
Component: S4methodsAssignee: R-core <R-core>
Status: CLOSED FIXED    
Severity: enhancement CC: jmc
Priority: P5    
Version: R 3.0.2   
Hardware: Other   
OS: Linux   
Attachments: Fixes for the four reported issues
Revision 2 of the patch

Description Michael Lawrence 2014-02-22 13:10:46 UTC
Created attachment 1567 [details]
Fixes for the four reported issues

There are at least four issues with the convenient call-oriented help syntax ?generic(arg1, ...). Note in the reports below I'm excluding the error that the documentation (obviously) does not exist. I'm only including the warning that indicates the selected signature is incorrect.

## uses ANY instead of missing
setGeneric("f", function(x, y) standardGeneric("f"))
setMethod("f", c("numeric", "missing"), function(x, y) x)
?f(1)
In .helpForCall(topicExpr, parent.frame()) :
  no method defined for function 'f' and signature 'x = "numeric", y = "ANY"'

## "..." is not handled
setGeneric("f", function(...) standardGeneric("f"))
setMethod("f", "numeric", function(...) c(...))
?f(1,2)
In .helpForCall(topicExpr, parent.frame()) :
  no method defined for function 'f' and signature '... = "ANY"'

## defaults in the generic formal arguments are not considered
setGeneric("f", function(x, y=0) standardGeneric("f"))
setMethod("f", c("numeric", "numeric"), function(x, y) x+y)
?f(1)
In .helpForCall(topicExpr, parent.frame()) :
  no method defined for function 'f' and signature 'x = "numeric", y = "ANY"'

## Objects with S3 classes fail earlier
setGeneric("f", function(x) standardGeneric("f"))
setMethod("f", "numeric", function(x) x)
setOldClass(c("foo", "numeric"))
n <- structure(1, class=c("foo", "numeric"))
?f(n)
Error in .helpForCall(topicExpr, parent.frame()) : 
  more elements supplied than there are to replace

I've attached a patch to fix these four issues.
Comment 1 Michael Lawrence 2014-02-22 22:36:36 UTC
Created attachment 1568 [details]
Revision 2 of the patch

Fixed the patch to handle case where "..." is in the generic formals, but is missing in the call.
Comment 2 John Chambers 2014-02-23 16:40:28 UTC
Thanks for the contribution.

Unless someone else gets to it first, I won't likely have time to check it out before the release of 3.0.3
Comment 3 Brian Ripley 2014-03-03 11:59:32 UTC
The examples are not fully testable: there is no documentation supplied.

Applied in R-devel: please test.
Comment 4 Michael Lawrence 2014-03-03 14:14:58 UTC
Seems to work now, thanks. Some tests (and errors from unpatched):

library(IRanges)
?rbind(DataFrame())
Error in .helpForCall(topicExpr, parent.frame()) : 
  no documentation for function 'rbind' and signature '... = "ANY"'

library(rtracklayer)
?import("my.gff")
Error in .helpForCall(topicExpr, parent.frame()) : 
  no documentation for function 'import' and signature 'con = "character", format = "ANY", text = "ANY"'
In addition: Warning message:
In .helpForCall(topicExpr, parent.frame()) :
  no method defined for function 'import' and signature 'con = "character", format = "ANY", text = "ANY"'

f <- structure("my.gff", class=c("myFileType", "character"))
?import(f)
Error in .helpForCall(topicExpr, parent.frame()) : 
  more elements supplied than there are to replace

These should all bring up documentation in patched.