Bug 16188 - stopifnot() should make it look like error came from its caller
Summary: stopifnot() should make it look like error came from its caller
Status: NEW
Alias: None
Product: R
Classification: Unclassified
Component: Language (show other bugs)
Version: R 3.1.2
Hardware: Other Other
: P5 enhancement
Assignee: R-core
URL:
Depends on:
Blocks:
 
Reported: 2015-02-04 19:45 UTC by Bill Dunlap
Modified: 2015-02-04 19:45 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Bill Dunlap 2015-02-04 19:45:44 UTC
Currently, if stopifnot(expr) discovers a problem it does not print where the error came from, as if its call to stop() had call.=FALSE in it. 
  > f <- function(x) stopifnot(length(x)==1, x>0)
  > f(-1)
  Error: x > 0 is not TRUE

It think it would make stopifnot more useful if it changed what I assume is something like
  stop(message, call.=FALSE)
to
  stop(simpleError(message, sys.call(-1)))
so we would see where the error came from
  > f(-1)
  Error in f(-1) : x > 0 is not TRUE

One could make call=sys.call(-1) an argument to stopifnot() so one could chain together commonly used checks.  The chaining would not be trivial since it must
use substitute() to make the text for the error message.