Skip to content

asking for advice on how to catch nonexistent list elements

1 message · Tamas K Papp

#
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
[1] 12
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