I was wondering how one is able to produce error messages in R, especially from within a function?
Asked
Active
Viewed 8.9k times
72
-
4It's not exactly an answer (that's why I make it a comment here) to @petermeissner question, but surely often overlooked and helpful in this context: `geterrmessage()` returns the last error message, enabling you to pass error messages from other functions (used within your own functions) around. Quite helpful when used with `tryCatch`. – Matt Bannert Dec 23 '16 at 10:05
2 Answers
128
Since you don't specify what you really want, all I just can say is take a look at
?message # prints a message but not stop execution
?warning # prints a warning message but not stop execution
?stop # stops execution of the current expression and executes an error action.

Jilber Urbina
- 58,147
- 10
- 114
- 138
49
Simply include stop()
inside your function/script
If you'd like an error message, include it inside stop()
like so
stop("This is an error message")

stevec
- 41,291
- 27
- 223
- 311