[R] difficulties with "setMethod"

Prof Brian Ripley ripley at stats.ox.ac.uk
Wed Jul 18 07:44:23 CEST 2007


On Tue, 17 Jul 2007, Nils Rüfenacht wrote:

> Dear all!
>
> I do definetley have some difficulties. Here is my code:
>
>> setMethod("write",
> +             signature(object = "KMatrix", path = "character"),
> +             function(object,path){
> +             write.table(object at data,path,row.names=FALSE, sep = "\t")
> +             }
> +             )
> error in match.call(fun, fcall) : unused argument(s) (object =
> "KMatrix", path = "character")
>>
>
> "KMatrix" is an extension of some data.frame object, i.e. it's a
> data.frame (KMatrix at data) with some additional slots (e.g. KMatrix at Size)
>
> What's wrong with my setMethod?

Take a look at the existing function 'write':
> write
function (x, file = "data", ncolumns = if (is.character(x)) 1 else 5,
     append = FALSE, sep = " ")
cat(x, file = file, sep = c(rep.int(sep, ncolumns - 1), "\n"),
     append = append)

You are trying to set a method for it with completely different arguments.

I am not sure what you are trying to achieve by this: it would look more 
natural to set a write.table() method since no one is going to call 
write() on the data frames you are wishing to 'extend'.

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595


More information about the R-help mailing list