How to return a error message in R?

R

R Problem Overview


I was wondering how one is able to produce error messages in R, especially from within a function?

R Solutions


Solution 1 - R

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.

Solution 2 - R

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")

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionpetermeissnerView Question on Stackoverflow
Solution 1 - RJilber UrbinaView Answer on Stackoverflow
Solution 2 - RstevecView Answer on Stackoverflow