Bug 15338 - alist enhancement request
Summary: alist enhancement request
Status: UNCONFIRMED
Alias: None
Product: R
Classification: Unclassified
Component: Language (show other bugs)
Version: R 3.0.0
Hardware: All All
: P5 enhancement
Assignee: R-core
URL:
Depends on:
Blocks:
 
Reported: 2013-06-07 00:14 UTC by eduard.antonyan
Modified: 2013-09-06 00:42 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description eduard.antonyan 2013-06-07 00:14:18 UTC
alist fails in the following scenario:

> test = function(...) {alist(...)}
> test(1,2,3)
[[1]]
...

the following will fix the problem:

> alist = function(...) match.call(expand.dots = FALSE)[["..."]]
> test = function(...) {alist(...)}
> test(1,2,3)
[[1]]
[1] 1

[[2]]
[1] 2

[[3]]
[1] 3
Comment 1 Duncan Murdoch 2013-06-07 00:48:42 UTC
The help page for alist() says that it doesn't evaluate its arguments, so I don't see the bug here.
Comment 2 eduard.antonyan 2013-06-07 15:49:00 UTC
Neither would the proposal function, except that it would make alist behave smarter in the example scenario.

Here's to show that normally it would behave the same way (and would not evaluate the expressions):

> alist = function(...) match.call(expand.dots = FALSE)[["..."]]
> alist(4+5,sin(x))
[[1]]
4 + 5

[[2]]
sin(x)
Comment 3 Duncan Murdoch 2013-06-07 15:54:57 UTC
Okay, so I've marked this as an enhancement request.
Comment 4 Peter Meilstrup 2013-09-06 00:42:35 UTC
A better way to get the desired effect is to use the expressions that are already packaged in promises, rather than bypassing the promises using stack inspection functions like match.call or sys.call. (Stack Inspection Never Does What You Want.)

alist <- function(...) substitute(list(...))[-1]

Demonstration of the where existing and proposed alists fail:

f1 <- function(...) f3(..., f=1+2)
f2 <- function(...) alist(..., e=x+y)

alist_existing <- function(...) as.list(sys.call()[-1L])
alist_proposed <- function(...) as.list(match.call(expand.dots=FALSE)[["..."]])
alist_fixed <- function(...) as.list(substitute(list(...))[-1])

#> alist <- alist_existing; f1(a="foo")
#[[1]]
#...
#
#$e
#x + y

> alist <- alist_proposed; f1(a="foo")
#$a
#[1] "foo"
#
#$f
#..2
#
#$e
#x + y

> alist <- alist_fixed; f1(a="foo")
#$a
#[1] "foo"
#
#$f
#1 + 2
#
#$e
#x + y