Skip to content
Prev 24761 / 63424 Next

Error Reporting

On 4/23/2007 7:23 PM, ivo welch wrote:
I think this message usually arises when you're doing something like

 > vars <- NA
 > df[1, vars]
Error in `[.data.frame`(df, 1, vars) : undefined columns selected

so the message is trying to tell you that there isn't any name 
available.  Conceivably the message could be clearer (e.g. in this 
specific case, "NA in column selection"), but that may not be the only 
way this error could arise.
>
 > joke.R:22: Error in `[.data.frame`(x, r, vars, drop = drop) :
 >         undefined columns selected: "non.existing.name" in 
"data.frame.name"
 >

That's quite difficult.  The parser knows line numbers, and can report 
them (as of 2.5.0), but these aren't kept when the lines are evaluated. 
  The sequence is:

read the file
parse it into a list of expressions
evaluate it

Parsing errors can report line numbers, but the evaluator doesn't keep them.

This means R doesn't have any idea what line caused a particular error. 
  In principle it could (e.g. by keeping line number info in functions), 
but it's tricky to get right, because there are so many ways to modify 
expressions after parsing.

There are limitations to the parser line number reporting (e.g. in a 
package, all source files are concatenated before parsing; if you have a 
syntax error you'll see the report about the concatenated file line 
number, not the original source file line number).  I'd say fixing those 
is the first priority.  My long range goal is to provide support for 
source-level debugging, which has requirements similar to the error 
reports you want:  they may come at the same time.  I'd guess this won't 
happen in 2.6.0, but you never know.

Duncan Murdoch