Skip to content
Back to formatted view

Raw Message

Message-ID: <Pine.GSO.4.21.0005310921090.689-100000@atlas.biostat.washington.edu>
Date: 2000-05-31T16:30:46Z
From: Thomas Lumley
Subject: no warning with NULL component in data.frame
In-Reply-To: <3.0.32.20000531180745.00909db0@162.38.183.200>

On Wed, 31 May 2000, Emmanuel Paradis wrote:


> I sent a message a few days ago about NULL components in list or
> data.frame. To reiterate, if I have a list or a data.frame, and try to
> manipulate some elements using the $ symbol, no warning is given if the
> elements do not exist.

"It's not a bug, it's a feature"

You can do is.null(list$component) to test very efficiently whether the
component is there, which would be hard if it gave an error. Also, it
turns out to be useful to be able to handle a list which may have missing
components without a lot of special cases and without errors.

Anyway, it's a fairly fundamental part of the language.

There might be a case for warning if you access a non-existent element of
a data frame. The problem here is that a lot of correct and functional 
code probably does access non-existent elements and the warnings would
get annoying.

Accessing non-existent dataframe columns with "[" does give an error, so
you could do that instead.

>data(trees)
>trees$aardvark
NULL
>trees[,"aardvark"]
Error in [.data.frame(trees, , "aardvark") : 
        subscript out of bounds


	-thomas

Thomas Lumley
Assistant Professor, Biostatistics
University of Washington, Seattle

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._