In our usage of R for a non-trivial data analysis and estimation project, we've been repeatedly burnt by how tolerant R is toward misspelled or missing columns in a data frame. Typical example is calculating the weighted mean of a variable MYVAR in a data frame using another variable WEIGHT for weights:
m <- weighted.mean(tbl$MYVAR, w = tbl$WEIGHT, na.rm = TRUE)
Suppose I make a typo in the WEIGHT name in the operation above. What will happen in that R will expand my misspelled column into NULL and will use it for performing the weighted mean resulting in a non-weighted one.
Therefore, the question: is there any way to make R treat attempts to "read" a non-existent variables in a data frame as an error?