R-devel's ...names() questions

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

R-devel's ...names() questions

R devel mailing list
Am am missing something or does the new ...names() in R-devel not work
right?

> a <- function(x, ...) ...names()
> a(a=stop("a"), b=stop("b"))
[1] "a" ""
> a(stop("x"), stop("unnamed"), c=stop("c"), d=stop("d"))
[1] NA "" ""

> version
               _
platform       x86_64-pc-linux-gnu
arch           x86_64
os             linux-gnu
system         x86_64, linux-gnu
status         Under development (unstable)
major          4
minor          1.0
year           2020
month          05
day            19
svn rev        78492
language       R
version.string R Under development (unstable) (2020-05-19 r78492)
nickname       Unsuffered Consequences

The following seems to do the right thing
alt...names <- function() evalq(names(substitute(...())),
envir=parent.frame())

However I wonder if it would be better to give the user a function, say
...args_unevaluated(...) to get the unevaluated ... arguments directlly
without having to know about the substitute(...()) trick.   Then the user
could get the length, the n'th, or the names using the usual length(), [[,
and names() functions instead of ...length(), ...elt(), and ...names().

Bill Dunlap
TIBCO Software
wdunlap tibco.com

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: R-devel's ...names() questions

Martin Maechler
>>>>> William Dunlap via R-devel
>>>>>     on Fri, 22 May 2020 11:53:12 -0700 writes:

    > Am am missing something or does the new ...names() in R-devel not work
    > right?

No, you are not missing anything, and you are right.
Thank you for the report!

Martin

    >> a <- function(x, ...) ...names()
    >> a(a=stop("a"), b=stop("b"))
    > [1] "a" ""
    >> a(stop("x"), stop("unnamed"), c=stop("c"), d=stop("d"))
    > [1] NA "" ""

    >> version
    > _
    > platform       x86_64-pc-linux-gnu
    > arch           x86_64
    > os             linux-gnu
    > system         x86_64, linux-gnu
    > status         Under development (unstable)
    > major          4
    > minor          1.0
    > year           2020
    > month          05
    > day            19
    > svn rev        78492
    > language       R
    > version.string R Under development (unstable) (2020-05-19 r78492)
    > nickname       Unsuffered Consequences

    > The following seems to do the right thing
    > alt...names <- function() evalq(names(substitute(...())),
    > envir=parent.frame())

    > However I wonder if it would be better to give the user a function, say
    > ...args_unevaluated(...) to get the unevaluated ... arguments directlly
    > without having to know about the substitute(...()) trick.   Then the user
    > could get the length, the n'th, or the names using the usual length(), [[,
    > and names() functions instead of ...length(), ...elt(), and ...names().

    > Bill Dunlap
    > TIBCO Software
    > wdunlap tibco.com

    > [[alternative HTML version deleted]]

    > ______________________________________________
    > [hidden email] mailing list
    > https://stat.ethz.ch/mailman/listinfo/r-devel

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel