[Rd] S4 and connection slot [Sec=Unclassified]
Wacek Kusnierczyk
Waclaw.Marcin.Kusnierczyk at idi.ntnu.no
Tue Jun 30 11:11:25 CEST 2009
Martin Morgan wrote:
[...]
>
> ## Attempt two -- initialize
> setClass("Element",
> representation=representation(conn="file"))
>
> setMethod(initialize, "Element", function(.Object, ..., conn=file()) {
> callNextMethod(.Object, ..., conn=conn)
> })
>
> new("Element")
> ## oops, connection created but not closed; gc() closes (eventually)
> ## but with an ugly warning
> ## > gc()
> ## used (Mb) gc trigger (Mb) max used (Mb)
> ## Ncells 717240 38.4 1166886 62.4 1073225 57.4
> ## Vcells 37333395 284.9 63274729 482.8 60051033 458.2
> ## > gc()
> ## used (Mb) gc trigger (Mb) max used (Mb)
> ## Ncells 715906 38.3 1166886 62.4 1073225 57.4
> ## Vcells 37335626 284.9 63274729 482.8 60051033 458.2
> ## Warning messages:
> ## 1: closing unused connection 3 ()
>
> setClass("ElementX", contains="Element")
> ## oops, two connections opened (!)
yes, that's because of the nonsense double call to the initializer while
creating a subclass. the conceptual bug in the s4 system leads to this
ridiculous behaviour in your essentially correct and useful pattern.
vQ
More information about the R-devel
mailing list