[Rd] The default behaviour of a missing entry in an environment

From: Trishank Karthik Kuppusamy <tk47_at_nyu.edu>
Date: Fri, 13 Nov 2009 14:03:48 -0500


Greetings everyone,

I have a question about the default behaviour of a missing entry in an environment. Let us look at the following sequence of R statements:

> e <- new.env()
> e$a <- 1
> e$a
[1] 1
> e$b

NULL
>

I think I understand the logic for returning NULL to a missing entry in an environment, but I do not think that it is fully justified. I am sure that the R developers must have seen this argument before, but I wish to call for attention to this problem again, because I think that it is important to the default safety of the R programming language.

I suppose that one could argue that a good R programmer must be careful not to use NULL in any of his environment entries, but I think it is better to remove altogether this burden from the programmer and simply raise a good, old-fashioned exception when the "$" operator encounters a missing entry in an environment. The biggest advantage is that it will easily eliminate a whole class of programming error. The biggest disadvantage is that it is not backwards-compatible with old R programs.

I suppose a personal solution would be to simply redefine the "$" operator in my programs. However, I really do think that the default safety of an R environment matters very much. At the very least, it would be nice to be able to configure the safety of a new environment, perhaps through a parameter.

-Trishank



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Fri 13 Nov 2009 - 19:07:39 GMT

This archive was generated by hypermail 2.2.0 : Fri 13 Nov 2009 - 19:50:24 GMT