Different behavior when passing empty multipoint arguments

This answer raised the question of how the ellipsis function in Rprocesses empty arguments. Apparently, an empty argument in ...works sometimes (see lapplyversion below), but not at other times (see sapplyversion). Here is an example:

lst <- list(x=matrix(1))
lapply(lst, "[", 1, )
# $x
# [1] 1
sapply(lst, "[", 1, )
# Error in lapply(X = X, FUN = FUN, ...) : 
#   argument is missing, with no default

From what I can tell, it sapplyactually just reuses arguments ...when called lapply. So I don’t understand why it lapplyworks, but sapplyno. Can anyone explain this behavior.

The certificate sapplystates that

sapply (*, simplify = FALSE, USE.NAMES = FALSE) is equivalent to lapply (*).

However, I get the same results as above for the following:

lapply(lst, "[", i=1, j=)
sapply(lst, "[", i=1, j=, simplify=FALSE, USE.NAMES=FALSE)

, , TRUE , , , . , lapply, , sapply.

+4
1

C, , , sapply lapply . , , - .

, sapply: https://github.com/SurajGupta/r-source/blob/master/src/library/base/R/sapply.R

lapply: https://github.com/SurajGupta/r-source/blob/master/src/library/base/R/lapply.R

, sapply lapply, simplify2array, , , .

lapply .Internal(lapply(X,FUN)), do_lapply C : https://github.com/SurajGupta/r-source/blob/91aaa43312da6b0e6906ef221fd7756dc0459843/src/main/apply.c

, sapply SEXP args, ... SEXP args sapply sapply(lst, "[", , 1, j=, simplify=FALSE, USE.NAMES=FALSE, . . lapply , SEXP args, 1, j= .

, , C R, , , nitty-gritty.

, - , , - R-devel.

+1

All Articles