From wdunl@p @ending from tibco@com  Thu May  3 17:01:53 2018
From: wdunl@p @ending from tibco@com (William Dunlap)
Date: Thu, 3 May 2018 08:01:53 -0700
Subject: [Rd] length of `...`
In-Reply-To: <d0b68216-4922-2249-e5e6-1589345dc6d7@kogentum.hu>
References: <d0b68216-4922-2249-e5e6-1589345dc6d7@kogentum.hu>
Message-ID: <CAF8bMcaRW88VdyXw-kmCa9dw-awBiNiU+j+nktLRACCj4grPdQ@mail.gmail.com>

In R-3.5.0 you can use ...length():
  > f <- function(..., n) ...length()
  > f(stop("one"), stop("two"), stop("three"), n=7)
  [1] 3

Prior to that substitute() is the way to go
  > g <- function(..., n) length(substitute(...()))
  > g(stop("one"), stop("two"), stop("three"), n=7)
  [1] 3

R-3.5.0 also has the ...elt(n) function, which returns
the evaluated n'th entry in ... , without evaluating the
other ... entries.
  > fn <- function(..., n) ...elt(n)
  > fn(stop("one"), 3*5, stop("three"), n=2)
  [1] 15

Prior to 3.5.0, eval the appropriate component of the output
of substitute() in the appropriate environment:
  > gn <- function(..., n) {
  +   nthExpr <- substitute(...())[[n]]
  +   eval(nthExpr, envir=parent.frame())
  + }
  > gn(stop("one"), environment(), stop("two"), n=2)
  <environment: R_GlobalEnv>




Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Thu, May 3, 2018 at 7:29 AM, D?nes T?th <toth.denes at kogentum.hu> wrote:

> Hi,
>
>
> In some cases the number of arguments passed as ... must be determined
> inside a function, without evaluating the arguments themselves. I use the
> following construct:
>
> dotlength <- function(...) length(substitute(expression(...))) - 1L
>
> # Usage (returns 3):
> dotlength(1, 4, something = undefined)
>
> How can I define a method for length() which could be called directly on
> `...`? Or is it an intention to extend the base length() function to accept
> ellipses?
>
>
> Regards,
> Denes
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

	[[alternative HTML version deleted]]




[Rd] length of `...`
William Dunlap