From tpapp at Princeton.EDU  Wed Feb 28 03:15:27 2007
From: tpapp at Princeton.EDU (Tamas K Papp)
Date: Tue, 27 Feb 2007 21:15:27 -0500
Subject: [Rd] asking for advice on how to catch nonexistent list elements
Message-ID: <20070228021527.GA4856@pu100877.student.princeton.edu>

Hi,

I am sorry if this is documented or in the archives somewhere, I tried
searching and could not find anything.

When using the $ operator to get a nonexistent element (or if you
prefer, all elements are defined as NULL by default) of a list, it
returns NULL, eg

> a <- list(maximum=12)
> a$maximum
[1] 12
> a$maxium  # typo
NULL

I know that this is the documented behavior of $, so this is
definitely not a bug.  But it leads to bugs that are quite elusive: an
error will only be generated when some function eventually chokes on
NULL.

I would like to know how people cope with that, and if there is a way
to generate an error message (at least when debugging code) for the
typo above.

Thanks,

Tamas



[Rd] asking for advice on how to catch nonexistent list elements
Tamas K Papp