Re: R-alpha: misc. 0.14

Thomas Lumley (
Tue, 3 Dec 1996 09:10:36 -0800 (PST)

Date: Tue, 3 Dec 1996 09:10:36 -0800 (PST)
From: Thomas Lumley <>
To: Paul Gilbert <>
Subject: Re: R-alpha: misc. 0.14
In-Reply-To: <>

On Wed, 4 Dec 1996, Paul Gilbert wrote:
> 6/ I see that setting a list element to NULL has been fixed in 0.14 so
> that the class information is not lost when an element is removed. But
> if 
> z <- list(a=1:3, b:2:4)
> then
> z[["b"]] <- NULL
> makes z a list with an element b which is NULL whereas 
> z$b <- NULL 
> removes b from the structure. For most purposes this probably doesn't
> matter but I suspect it is not intentional.

I think this is intentional (or at least useful).  z$b<-NULL is the only 
way to remove things from lists by name.  This is essential in the model 
formula processing so that we can turn a call like
lm(Y~z+x,weights=w,data=frame, singular.ok=TRUE,x=TRUE) into
model.frame(Y~z+x,weights=w,data=frame) wihout evaluating the arguments 
(thus allowing w to be evaluated in the supplied data frame)

On the other hand, it is useful to be able to have NULL as an element of 
a list, as otherwise the list components have to have names.

> A second difference between $<- and [[<- still causes me more trouble:
> > z <- list(a=1:3)
> > z[["b"]] <- 2:4
> Error: subscript out of bounds
> > z$b <- 2:4
> > 
> so I am still using my own special version of "[[<-". In the long run 
> this is not a good thing for me to do because it will eventually result
> in other conflicts, so please let me know if this is a design feature
> rather than a bug.

I don't really like this behaviour either. It is not compatible with S. 
There is one debugging advantage to this behaviour: if you think that z 
has a component called "b" and it doesn't, you will notice. As z$b works 
you can avoid the issue in most cases.  The only really nasty situation 
is when you have a character variable and want to set a list component 
with that name.  It is quite difficult to construct a call to $ that will 

thomas lumley
UW biostatistics
r-testers mailing list -- For info or help, send "info" or "help",
To [un]subscribe, send "[un]subscribe"
(in the "body", not the subject !)  To: