From jeff.a.ryan at gmail.com  Wed Dec  3 22:22:24 2008
From: jeff.a.ryan at gmail.com (Jeff Ryan)
Date: Wed, 3 Dec 2008 15:22:24 -0600
Subject: [Rd] reduce limit number of arguments in methods:::cbind
In-Reply-To: <20081203202807.228a879e@mimi>
References: <20081203202807.228a879e@mimi>
Message-ID: <e8e755250812031322n2d94b819ha05d97cf2ff50e93@mail.gmail.com>

My 2c:

The real issue for me is that this approach to handling S4 objects by
altering R functions for the worse is incorrect. (by calling
bind_activation)

m <- matrix(1:2e6L)  # 2 million obs
> system.time(cbind(m,m))
   user  system elapsed
  0.027   0.017   0.044
> methods:::bind_activation(TRUE)
[1] FALSE

# the additional overhead of cbind is now damaging to cbind S3 methods
> system.time(cbind(m,m))
   user  system elapsed
  0.043   0.034   0.077 [~175% of the original time]

Wouldn't a better near-term approach involve writing S3 methods to dispatch on.

> methods:::bind_activation(FALSE)
> library(Matrix)
> M <- Matrix(1:10)
> cbind(M,M)
     M M
[1,] ? ?

> cbind.dgeMatrix <- function(..., deparse.level=1) methods:::cbind(..., deparse.level=deparse.level)
> cbind(M,M)
10 x 2 Matrix of class "dgeMatrix"
      [,1] [,2]
 [1,]    1    1
 [2,]    2    2
 [3,]    3    3
 [4,]    4    4
 [5,]    5    5
 [6,]    6    6
 [7,]    7    7
 [8,]    8    8
 [9,]    9    9
[10,]   10   10

# this approach "does no harm" to regular S3 methods
> system.time(cbind(m,m))
   user  system elapsed
  0.028   0.017   0.045

Obviously this negates part of the S4 dispatch value, but that can be
had by calling cbind2 directly.


Jeff

-- 
Jeffrey Ryan
jeffrey.ryan at insightalgo.com

ia: insight algorithmics
www.insightalgo.com



[Rd] reduce limit number of arguments in methods:::cbind
Jeff Ryan