How can I create a standard error message in R? For example, if multiple functions should return the following error message in some condition:
stop("This is an error")
My first thought was creating something like:
err_fun = function() stop("This is an error")
foo = function(a){ if(!a) err_fun()}
But this approach doesn't point the error location correctly (which makes sense)
foo(FALSE)
#Error in err_fun() : This is an error
The expected outcome would be
#Error in foo(FALSE) : This is an error
How to I properly write a "shortcut" for an error message so I don't have to write it every time and have a cleaner code?