I'm aware that NULL values in lists can sometimes trip people up. I'm curious why in a specific instance lapply
and rapply
seem to treat NULL
values differently.
l <- list(a = 1, c = NULL, d = 3)
lapply(l,is.null)
$a
[1] FALSE
$c
[1] TRUE
$d
[1] FALSE
So far so good. How about if we do the exact same thing with rapply
?
rapply(l, is.null, how = "replace")
$a
[1] FALSE
$c
list()
$d
[1] FALSE
This example is very simple and non-recursive, but you see the same behavior in rapply
with nested lists.
My question is why? If, as advertised in ?rapply
, it is a 'recursive version of lapply', why do they behave so differently in this case?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…