Skip to content
Prev 206574 / 398503 Next

Error: object of type 'closure' is not subsettable

I thought it would be possible to make rep() work for functions
by writing a method for the function class.  I tried:

rep.function <- function(x,...) {
    times <- as.list(...)[[1]]
    rslt  <- vector("list",times)
    rslt[1:times] <- list(x)
    rslt
}

But then doing

rep(sin,2)

still gave an error --- Error: object of type 'builtin' is not  
subsettable

Note the difference: ``builtin'' rather than ``closure''.

I then noticed that there is no generic function for rep, although
there are ***methods*** for rep.  I don't understand this at all!

So I did:

rep.default <- rep
rep <- function(x,...){UseMethod("rep")}

Having taken these steps, rep(sin,2) worked as expected.

But why doesn't rep() have a generic form?  And how can there
be methods ***without*** a generic?  Can anyone explain the
issues to me, preferably in terms that are comprehensible to
the human mind (which is what I'm equipped with)?

	cheers,

		Rolf Turner
On 14/01/2010, at 2:24 PM, Gabor Grothendieck wrote:

            
######################################################################
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}