Description Usage Arguments Details Value See Also Examples
Function to be used as an alternative for rapply (recursive version of lapply)
It differs in two important aspects:
It handles NULL as a value, instead of seeing it as an empty list. See examples for comparison
If you set inclLists to TRUE, it also applies fn over the lists itself
1 | simple_rapply(x, fn, ..., classes = "ANY", inclLists = "No")
|
x |
Any object, but usually a list (if not a list, the result is identical to calling fn(x, ...)) |
fn |
A function to apply over the elements of x |
... |
Additional arguments passed on to fn |
classes |
A character vector of class names, or "ANY" to match any class. Other classes are returned unmodified |
inclLists |
Should fn be also applied to the lists themselves? see 'Examples'. Can be FALSE, 'No', 'First', 'Last' or TRUE. First and Last apply fn to the list themselves either before or after applying to the elements themselves. TRUE and FALSE are for backward compatibility, and are casted to 'No' and 'First', with a warning |
Further note that this implementation is comparable to running rapply with how='replace'
a list with the same structure as x, with fn applied over the elements
rapply
1 2 3 4 5 6 7 8 9 | L <- list(l=list(m=4, o=NULL, n=3), p=list(NULL), q=c(t=6, r=4,s=5), k=1)
rapply(L, is.null, how='replace')
any(unlist(rapply(L, is.null, how='replace')))
simple_rapply(L, is.null)
any(unlist(rapply(L, is.null)))
rapply(L, function(x) {if(!is.null(names(x))) x[order(names(x))] else x}, how='replace')
simple_rapply(L, function(x) {if(!is.null(names(x))) x[order(names(x))] else x})
simple_rapply(L, function(x) {if(!is.null(names(x))) x[order(names(x))] else x}, inclLists=TRUE)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.