File: stop.if.dots.R

package info (click to toggle)
r-cran-plotmo 3.7.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,400 kB
  • sloc: sh: 13; makefile: 2
file content (42 lines) | stat: -rw-r--r-- 1,589 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# stop.if.dots.R:

# stop.if.dots issues an an error message if any args in dots.
# We use it to test if any dots arg of the calling function was used, for
# functions that must have a dots arg (to match the generic method) but don't
# actually use the dots.  This helps the user catch mistyped or illegal args.

stop.if.dots <- function(...)
{
    dots <- match.call(expand.dots=FALSE)$...
    if(length(dots))
        dots.used.err(STOPFUNC=base::stop, MSG=": unrecognized", ...)
}

warn.if.dots <- function(...)
{
    dots <- match.call(expand.dots=FALSE)$...
    if(length(dots))
        dots.used.err(STOPFUNC=base::warning, MSG=" ignored", ...)
}
dots.used.err <- function(..., STOPFUNC, MSG) # utility for stop.if.dots and friends
{
    callers.name <- callers.name(n=2)
    dots <- match.call(expand.dots=FALSE)$...
    for(idot in seq_along(dots)) # STOPFUNC is either stop() or warning()
    {
        desc <- describe.dot(dots, idot)
        STOPFUNC(callers.name, MSG, desc, call.=FALSE)
    }
}
describe.dot <- function(dots, idot, n=4) # utility for dots.used.err
{
    nchar <- nchar(names(dots)[idot])
    if(length(nchar) && nchar > 0)
        return(sprint(" argument '%s'", names(dots[idot])))
    # the argument that was passed in dots is unnamed
    call <- call.as.char(n=4) # n=4 to describe call to caller of stop.if.dots
    sprint(" unnamed argument\n       The call was %s",
           paste0(strwrap(call,
                  width=max(40, max(25, getOption("width")-20)), exdent=25),
                  collapse="\n"))
}