6

I would like to use a function which exports errors into a .txt file. So far I have:

error.function <- function() {
cat(geterrmessage(), file="c:/bla.txt", append=TRUE)
}

then,

options("error"=error.function)

However, that only gives me the error without the corresponding line number May I ask for assistance in order to expand the error.function with information about the line number(my script in Rstudio begins with line1 and goes up to line 2500?

nrussell
  • 18,382
  • 4
  • 47
  • 60
  • What do you mean by row? Row of what? – A. Webb Aug 20 '15 at 18:04
  • the numeric index of the source aka row number...sorry –  Aug 20 '15 at 18:10
  • Possible duplicate of [R script line numbers at error?](http://stackoverflow.com/questions/1445964/r-script-line-numbers-at-error) – A. Webb Aug 20 '15 at 18:13
  • @A.Webb if I understand correctly they mean lines of a file they're reading?? – MichaelChirico Aug 20 '15 at 18:15
  • @Mamba if you're reading in a file, the `fread` command in the `data.table` package has a `verbose` option which _might_ help... you haven't really given us enough information to help there though... – MichaelChirico Aug 20 '15 at 18:16
  • Ok the error output is just an error. If you have an r Script with more than 2000 lines/rows/ that you just cant go through it every time...I just asked how to include that information about the corresponding `line/row'. I dont really understand what kind of additional information you need? I just need that reference from error to line :) thats it. –  Aug 20 '15 at 18:18
  • Mamba you might want to read http://stackoverflow.com/q/11666086/2886003 And changing a little bit your idea to find the error. You could also split your script in several smaller scripts to make it easier to known when an error occurs. – llrs Aug 20 '15 at 19:01
  • Other interesting posts are [here](http://stackoverflow.com/questions/1445964/r-script-line-numbers-at-error) and [here](http://stackoverflow.com/questions/3650444/r-script-line-numbers-at-error). I hope they help – llrs Aug 20 '15 at 19:03

0 Answers0