How to get R script line numbers at error?

Viewed 40588

If I am running a long R script from the command line (R --slave script.R), then how can I get it to give line numbers at errors?

I don't want to add debug commands to the script if at all possible; I just want R to behave like most other scripting languages.

6 Answers

You do it by setting

options(show.error.locations = TRUE)

I just wonder why this setting is not a default in R? It should be, as it is in every other language.

First, options(show.error.locations = TRUE) and then traceback(). The error line number will be displayed after #

Related