Re: [R] S4 object slot of type 'call'

From: Uwe Ligges <ligges_at_statistik.uni-dortmund.de>
Date: Mon, 28 May 2007 19:52:10 +0200

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



R-help_at_stat.math.ethz.ch 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. Received on Mon 28 May 2007 - 18:05:06 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 28 May 2007 - 19:31:52 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.