[R] S4 object slot of type 'call'

Uwe Ligges ligges at statistik.uni-dortmund.de
Mon May 28 19:52:10 CEST 2007



Prof Brian Ripley wrote:
> On Mon, 28 May 2007, Uwe Ligges wrote:
> 
>>
>>
>> Roberto Brunelli wrote:
>>> I'm using an S4 object with a slot of type 'call': I would like to be 
>>> able to initialize
>>> it with something like NULL or NA (indicating that there is no 
>>> information in the slot)
>>> but the value should comply with the fact that it must be of type call.
>>>
>>> Is there any simple way to obtain this?
>>
>>
>> This looks fine:
>>
>>
>> > setClass("testCall", representation = representation(call = "call"))
>> [1] "testCall"
>> > test <- new("testCall")
>> >
>> > test
>> An object of class "testCall"
>> Slot "call":
>> `<undef>`()
>>
>>
>>
>> Although, I found a bug while playing around:
>>
>> cl <- call("round", 10.5)
>> cl[] <- NULL
>> cl
>> ## CRASH using R-2.5.0 on Windows XP
> 
> Yes, well, what did you think that would do?
> 
> A call is a pairlist (a LANGSXP).  [] on a pairlist converts it to a 
> vector list, subsets, and for a LANGSXP converts back.  So you have
> a 0-length call, and lots of code assumes that a LANGSXP has length at 
> least one, including deparse (used in printing).

Sure. While starting to think about the topic I typed the above -- and 
then I thought it makes sense to report about the crash.


> cl <- call("round")
> cl[1] <- list(NULL)
> 
> might be what you were trying to get.

Yes, it is, thank you.

Uwe



More information about the R-help mailing list