Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R script line numbers at error? [duplicate]

Tags:

r

debugging

I found this post from a year ago, and I'm using R version 2.11.1 (2010-05-31), but still getting error messages without line numbers.

Any solution?

like image 711
David B Avatar asked Sep 06 '10 09:09

David B


1 Answers

The answers given there are still valid. Returning line numbers from a script ain't that straight-forward, but R can give you a lot more information on where the error can be found.

You could use the error options to save the info in a file, for example :

options(error = quote({
  sink(file="error.txt");
  dump.frames();
  print(attr(last.dump,"error.message"));
  traceback();
  sink();
  q()}))

The function findLineNum() could be used if you have the name of the file somewhere available. If you have the error message, you could do something like :

dump.frames()
x <- attr(last.dump,"error.message")
ll <- gsub("Error in (.*) : .*","\\1",x)
lln <- findLineNum(srcfile,ll)
like image 116
Joris Meys Avatar answered Nov 14 '22 23:11

Joris Meys