From brodie@g@@l@m @ending from y@hoo@com  Thu Jan 10 17:57:35 2019
From: brodie@g@@l@m @ending from y@hoo@com (brodie gaslam)
Date: Thu, 10 Jan 2019 16:57:35 +0000 (UTC)
Subject: [Rd] setClass accepts slot-mismatch between slots and prototype
 arguments
In-Reply-To: <CAF8bMcbPCvsWx2o3iTHpXGFAT=azDdMZXz7Uiznr_jOZBbyKcw@mail.gmail.com>
References: <CAF8bMcbPCvsWx2o3iTHpXGFAT=azDdMZXz7Uiznr_jOZBbyKcw@mail.gmail.com>
Message-ID: <396016809.9493101.1547139455425@mail.yahoo.com>

Indeed that was on oversight on my part.? It is surprising that things like this work:

> setClass('test', slots=c(a='ANY'), prototype=list(a=NULL, b='hello'))
> new('test')@b
[1] "hello"
> slotNames(new('test'))
[1] "a"

I'm planning a release of diffobj right now so I will fix this, but I agree that R should probably throw an error here.

Best,

B.




On Thursday, January 10, 2019, 11:30:13 AM EST, William Dunlap <wdunlap at tibco.com> wrote: 





I was installing the 'diffobj' package into TERR and got an error from the call
StyleSummary <- setClass("StyleSummary",
? slots=c(container="ANY", body="ANY", map="ANY"),
? prototype=list(
? ? container=function(x) sprintf("\n%s\n", paste0(x, collapse="")),
? ? body=identity,
? ? detail=function(x) sprintf("\n%s\n", paste0("? ", x, collapse="")),
? ? map=function(x) sprintf("\n%s", paste0("? ", x, collapse="\n"))
? ))
because the prototype contained components not in the slots list.? R does not complain about the mismatch, but new("StyleSummary") does name make something with a 'detail' slot.? Should this be an error?

I suspect that the package writer intended to include 'detail' in the slots argument.

Bill Dunlap
TIBCO Software
wdunlap tibco.com



[Rd] setClass accepts slot-mismatch between slots and prototype arguments
brodie gaslam