[R] S4 object slot of type 'call'

Prof Brian Ripley ripley at stats.ox.ac.uk
Mon May 28 19:20:05 CEST 2007


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).

cl <- call("round")
cl[1] <- list(NULL)

might be what you were trying to get.

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-help mailing list