R .call argument in stop function -
what use of .call argument in stop function?
the page (?stop) explains "call. logical, indicating if call should become part of error message.".
could 1 explain .call argument intuitive example?
thanks
just try yourself:
f = function () stop('foo') g = function () stop('bar', call. = false) f() # error in f(): foo g() # error: bar
… , compare output. that’s difference.
the use of argument when want hide irrelevant detail end user otherwise drown out actual error message or actively misleading.
for instance, i have package contains following functions1:
#' @export import = function (module, ...) { # … code here … module_path = find_module(module) # … more code here … } find_module = function (module) { # … code here … if (no_module_found) stop('unable load module ', module, '.', call. = false) }
now, can see function import
exported package, function find_module
isn’t. consequently user doesn’t know function, , should not know it: it’s irrelevant implementation detail. if hadn’t specified call. = false
in stop
above, error message have contained reference hidden function, have confused user of package.
1 that’s small lie, code different; earlier version of package did contain code.
Comments
Post a Comment