From bates at stat.wisc.edu  Wed Apr  7 23:13:05 2004
From: bates at stat.wisc.edu (Douglas Bates)
Date: Wed Apr  7 23:13:02 2004
Subject: [Rd] Re: [R] More user-friendly error message needed.
In-Reply-To: <D7A3CFD7825BD6119B880002A58F06C20680B22C@groexmb02.pfizer.com>
References: <D7A3CFD7825BD6119B880002A58F06C20680B22C@groexmb02.pfizer.com>
Message-ID: <6rbrm3ze3i.fsf@bates4.stat.wisc.edu>

"Warnes, Gregory R" <gregory_r_warnes@groton.pfizer.com> writes:

> Perhaps one could create a utility function 
> 
> 	has.element <- function(list, name) name %in% names(list)
> 
> and then have $ generate a warning (not an error!) when the named element
> does not exist.

Because of partial matching, list$name can return a result when 
your has.element function returns FALSE.

> lst = list(foo = 1:3, bar = LETTERS[1:3])
> lst$f
[1] 1 2 3
> has.element <- function(list, name) name %in% names(list)
> has.element(lst, "f")
[1] FALSE

Before we go too far in speculating about what the $ operator should
or should not return when the name is not matched, let's all remember
that the semantics of the $ operator explicitly state that it should
return NULL and, as Duncan wrote, there are many, many places in the
base code for R that depend upon this behavior.  Trust me - you really
don't want to change this.


[Rd] Re: [R] More user-friendly error message needed.
Douglas Bates