Bug 14883 - Missing argument for generic 'backsolve'
Missing argument for generic 'backsolve'
Status: RESOLVED FIXED
Product: R
Classification: Unclassified
Component: S4methods
R 2.15.0
ix86 (32-bit) Linux-Ubuntu
: P5 normal
Assigned To: R-core
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2012-04-17 08:25 UTC by Reinhard Furrer
Modified: 2012-04-24 02:01 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Reinhard Furrer 2012-04-17 08:25:18 UTC
Consider the following lines:

r <- diag(3)
x <- rep(1,3)
backsolve(r,x)

setClass("M")
setMethod("backsolve", "M", function(r,x,...) r)

backsolve(r,x)

The last call produces an error, related to the generic definition. IMHO, a default argument k=ncol(r) is missing:

setGeneric("backsolve", function(r, x, k = ncol(r), upper.tri = TRUE, 
             transpose = FALSE, ...)  standardGeneric("backsolve"),
     useAsDefault = function(r, x, k = ncol(r), upper.tri = TRUE, 
           transpose = FALSE, ...)  base::backsolve(r, x, k = k, 
                upper.tri = upper.tri, transpose = transpose, ...),
           signature = c("r", "x"))

Thanks!

Reinhard

PS: is there a reason, why no generic for forwardsolve is defined.

sessionInfo()
R version 2.15.0 (2012-03-30)
Platform: i686-pc-linux-gnu (32-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=C                 LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base
Comment 1 John Chambers 2012-04-24 02:01:15 UTC
Fixed in r-devel and 2.15.0 patched.  Thanks.

Re. forwardsolve().  Actually, the question is more why we bothered to have an implicit generic with different signature for backsolve().  Long ago, it was thought to be significantly inefficient to have extra arguments in the signature.  Not really true, and although it's hard to see how dispatching on anything other than r & x could make sense, it's not really worth an exception.

More to the point, the whole code for implicit generics is old-fashioned given the more natural behavior of setGeneric(), and should use the non-generic version directly.