From jeroenooms at gmail.com  Thu Jan  8 22:21:53 2015
From: jeroenooms at gmail.com (Jeroen Ooms)
Date: Thu, 8 Jan 2015 13:21:53 -0800
Subject: [Rd] RFC: getifexists() {was [Bug 16065] "exists" ...}
In-Reply-To: <54AE95F1.1050402@gmail.com>
References: <54AE6C53.8030702@gmail.com>
	<bug-16065-16@http.bugs.r-project.org/bugzilla/>
	<bug-16065-16-N2rAUyzVWO@http.bugs.r-project.org/bugzilla/>
	<21678.19158.736089.111281@stat.math.ethz.ch>
	<OF12891DEC.6A4C5E3F-ON85257DC7.004D34A7-85257DC7.004D34AB@american.edu>
	<54AE95F1.1050402@gmail.com>
Message-ID: <CABFfbXuYMo9ejpfKqTmVp5hnuepYRW3smyauoQaofLCf0zMJeA@mail.gmail.com>

On Thu, Jan 8, 2015 at 6:36 AM, Duncan Murdoch <murdoch.duncan at gmail.com> wrote:
>> val <- get(name, where, ..., value.if.not.found=NULL )   (*)
>
> That would be a bad idea, as it would change behaviour of existing uses of
> get().

Another approach would be if the "not found" behavior consists of a
callback, e.g. an expression or function:

  get(name, where, ..., not.found=stop("object ", name, " not found"))

This would cover the case of not.found=NULL, but also allows for
writing code with syntax similar to tryCatch

  obj <- get("foo", not.found = someDefaultValue())

Not sure what this would do to performance though.



[Rd] RFC: getifexists() {was [Bug 16065] "exists" ...}
Jeroen Ooms