Put this at the top of your executable Rscript file:
options(error = quote({
dump.frames(to.file=T, dumpto='last.dump')
load('last.dump.rda')
print(last.dump)
q()
}))
Example:
./somescript
Error: I fail!
$`stop("I fail!")`
<environment: 0x100ca5790>
attr(,"error.message")
[1] "Error: I fail!\n"
attr(,"class")
[1] "dump.frames"
Just kidding! You still can't get line numbers for errors in Rscripts but this is slightly more helpful.
Solution modified from StackOverflow question: R script line numbers at error?.
R is just so painful..