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

Jeroen Ooms jeroenooms at gmail.com
Thu Jan 8 22:21:53 CET 2015


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.



More information about the R-devel mailing list