[R] 'save' method for S4 class
Uwe Ligges
ligges at statistik.tu-dortmund.de
Thu Jul 18 22:43:56 CEST 2013
On 18.07.2013 20:23, Christofer Bogaso wrote:
> Hi Simon,
>
> Thanks for your pointer.
>
> However could you please explain what 'function(x, file_Path)
> standardGeneric("save")' means here?
It is the definition of the generic function for save()?
The underlying help files look quite
> rocket science for me!
So start reading about S4 seems to be essential, if you ask for S4
methods. Otherwise we cannot help, given you do not even understand the
code to define the generic function.
Uwe Ligges
>
> Thanks for your time.
>
> Thanks and regards,
>
>
> On Thu, Jul 18, 2013 at 4:32 PM, Simon Zehnder <szehnder at uni-bonn.de> wrote:
>
>> Hi Christopher,
>>
>> I think, that "save" is no generic function like "plot", "show", etc. So
>> at first you have to determine a generic.
>>
>> setGeneric("save", function(x, file_Path) standardGeneric("save"))
>>
>> Now your definition via setMethod.
>>
>>
>> Best
>>
>> Simon
>>
>>
>>
>> On Jul 18, 2013, at 12:09 PM, Christofer Bogaso <
>> bogaso.christofer at gmail.com> wrote:
>>
>>> Hello again,
>>>
>>> I am trying to define the 'save' method for my S4 class as below:
>>>
>>> setClass("MyClass", representation(
>>> Slot1 = "data.frame"
>>> ))
>>>
>>> setMethod("save", "MyClass", definition = function(x, file_Path) {
>>>
>>> write.table(x at Slot1, file = file_Path, append = FALSE,
>> quote = TRUE,
>>> sep = ",",
>>> eol = "\n", na = "NA", dec
>> = ".", row.names = FALSE,
>>> col.names = TRUE, qmethod
>> = c("escape", "double"),
>>> fileEncoding = "")
>>> })
>>>
>>> However while doing this I am getting following error:
>>>
>>> Error in conformMethod(signature, mnames, fnames, f, fdef, definition) :
>>> in method for ‘save’ with signature ‘list="MyClass"’: formal
>>> arguments (list = "MyClass", file = "MyClass", ascii = "MyClass",
>>> version = "MyClass", envir = "MyClass", compress = "MyClass",
>>> compression_level = "MyClass", eval.promises = "MyClass", precheck =
>>> "MyClass") omitted in the method definition cannot be in the signature
>>>
>>>
>>> Can somebody point me what will be the correct approach to define
>>> 'save' method for S4 class?
>>>
>>> Thanks and regards,
>>>
>>> ______________________________________________
>>> R-help at r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>
>>
>
> [[alternative HTML version deleted]]
>
>
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
More information about the R-help
mailing list