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

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Mon, 28 May 2007 18:20:05 +0100 (BST)

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

______________________________________________
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 - 17:27:05 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 - 18:31:10 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.