Skip to content
Prev 21756 / 63435 Next

Wish: keep names in mapply() result

Hello,

Charles Berry sent me (off-list) his proposal, which I find better
(after slight modification) than mine. I would say that proposed changes
make mapply even more consistent with (some) *apply* funcs in terms of
names. Patches to mapply.R and mapply.Rd are attached. I have runned
make check-all and it seems that there are no problems with this change.
I hope R core will find this worth to apply.

New behaviour without first ... as character:

l <- list(a=1, b=2)
k <- list(1)
mapply(FUN="+", l, k)
a b
2 3

mapply(FUN="+", l, k, USE.NAMES=FALSE)
[1] 2 3

mapply(FUN="+", l, k, SIMPLIFY=FALSE)
$a
[1] 2

$b
[1] 3

mapply(FUN="+", l, k, SIMPLIFY=FALSE, USE.NAMES=FALSE)
[[1]]
[1] 2

[[2]]
[1] 3

New behaviour with first ... as character _with_ names:

l <- c("1", "2")
names(l) <- c("a", "b")
mapply(FUN="paste", l, k)
    a     b
"1 1" "2 1"

mapply(FUN="paste", l, k, USE.NAMES=FALSE)
[1] "1 1" "2 1"

mapply(FUN="paste", l, k, SIMPLIFY=FALSE)
$a
[1] "1 1"

$b
[1] "2 1"

mapply(FUN="paste", l, k, SIMPLIFY=FALSE, USE.NAMES=FALSE)
[[1]]
[1] "1 1"

[[2]]
[1] "2 1"

New behaviour with first ... as character _without_ names:

l <- c("1", "2")
mapply(FUN="paste", l, k)
    1     2
"1 1" "2 1"

mapply(FUN="paste", l, k, USE.NAMES=FALSE)
[1] "1 1" "2 1"

mapply(FUN="paste", l, k, SIMPLIFY=FALSE)
$`1`
[1] "1 1"

$`2`
[1] "2 1"

mapply(FUN="paste", l, k, SIMPLIFY=FALSE, USE.NAMES=FALSE)
[[1]]
[1] "1 1"

[[2]]
[1] "2 1"

Regards, Gregor
Gregor Gorjanc wrote:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mapply.R.patch.gz
Type: application/x-gzip
Size: 446 bytes
Desc: not available
Url : https://stat.ethz.ch/pipermail/r-devel/attachments/20060831/80849894/attachment-0008.gz 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mapply.Rd.patch.gz
Type: application/x-gzip
Size: 438 bytes
Desc: not available
Url : https://stat.ethz.ch/pipermail/r-devel/attachments/20060831/80849894/attachment-0009.gz