From mdowle at mdowle.plus.com  Thu Jan  3 20:28:43 2013
From: mdowle at mdowle.plus.com (Matthew Dowle)
Date: Thu, 03 Jan 2013 19:28:43 +0000
Subject: [Rd] Bounty on Error Checking
Message-ID: <b072c553e64b4f47f775cec5a018c922@imap.plus.net>


Ivo,

That's standard R behaviour. But I've had similar bugs
as you.

If you really want to change it then one way would be to
create your own helper function, say strictselect(), or
shorter name and ensure to use that instead of [[ and $.

Or, how about something like this? :

> DF = data.frame(a=1:3,b=4:6)
> DF$foo
NULL
> DF[["foo"]]
NULL
> "$.data.frame" = "[[.data.frame" = function(x,...) {
     if (!..1 %in% names(x)) stop("Column not found!")
     else base::"[[.data.frame"(x,...)
   }
> DF$foo
Error in `$.data.frame`(DF, foo) : Column not found!
> DF[["foo"]]
Error in `[[.data.frame`(DF, "foo") : Column not found!
> DF[["newcol"]] <- 7:9
> DF
   a b newcol
1 1 4      7
2 2 5      8
3 3 6      9

Masking those methods in your .GlobalEnv shouldn't break
packages that may rely on missing columns returning NULL
because all packages now have namespaces. So this mask
should just affect your own code, iiuc.

You could place those masks into your Rprofile.site.

It was quickly typed and tested, and not thoroughly
thought through, so *it is just a straw man*.

Matthew



[Rd] Bounty on Error Checking
Matthew Dowle