Reputation: 59477
There is a handy option show.error.locations
in R that would show the source file & line where the error occured. I wonder if there is something like show.warning.locations
to do the same for warnings? Could be handy, for example:
> options(show.error.locations = TRUE)
> source ("data_b-rf.R")
Error in savePlot(paste(fn, "_varimp", sep = "_"), "png") (from data_b-rf.R#149) :
can only copy from 'X11(type="*cairo")' devices
In addition: Warning messages:
1: In grepl("\n", lines, fixed = TRUE) :
input string 48 is invalid in this locale
2: In randomForest.default(m, y, ...) :
The response has five or fewer unique values. Are you sure you want to do regression?
> options("show.error.locations")
$show.error.locations
[1] TRUE
> options("show.error.messages")
$show.error.messages
[1] TRUE
This will only write the location of the error, but not of those warnings. Is there any way to do this in R?
Upvotes: 4
Views: 3034
Reputation: 206207
As far as i know there is no way to enable line numbers for warnings. But you can turn warnings into errors with options(warn=2)
of course that will stop execution of a function but often if you're getting unexpected warnings it's a good idea to stop and find out why,
Upvotes: 11