[Rd] stopifnot() does not stop at first non-TRUE argument
Suharto Anggono Suharto Anggono
suharto_anggono at yahoo.com
Thu May 18 18:27:09 CEST 2017
>From an example in http://www.uni-muenster.de/ZIV.BennoSueselbeck/s-html/helpfiles/nargs.html , number of arguments in '...' can be obtained by
I now realize that sys.call() doesn't expand '...' when the function is called with '...'. It just returns the call as is. If 'stopifnot' uses sys.call() instead of match.call() , the following example behaves improperly:
g <- function(...) stopifnot(...)
On Thu, 18/5/17, Martin Maechler <maechler at stat.math.ethz.ch> wrote:
Subject: Re: [Rd] stopifnot() does not stop at first non-TRUE argument
Cc: r-devel at r-project.org
Date: Thursday, 18 May, 2017, 3:03 PM
>>>>> Suharto Anggono Suharto Anggono via R-devel <r-devel at r-project.org>
>>>>> on Tue, 16 May 2017 16:37:45 +0000 writes:
> switch(i, ...)
> extracts 'i'-th argument in '...'. It is like
> eval(as.name(paste0("..", i))) .
Yes, that's neat.
It is only almost the same: in the case of illegal 'i'
the switch() version returns
whereas the version we'd want should signal an error, typically
the same error message as
> t2 <- function(...) ..2
Error in t2(1) (from #1) : the ... list does not contain 2 elements
> Just mentioning other things:
> - For 'n',
> n <- nargs()
> can be used.
I know .. [in this case, where '...' is the only formal argument of the function]
> - sys.call() can be used in place of match.call() .
Hmm... in many cases, yes.... notably, as we do *not* want the
argument names here, I think you are right.
More information about the R-devel