Description Usage Arguments Details Examples
This function removes all elements evaluated to be
TRUE
by an indicator function. The removal can be recursive
so that the resulted list surely does not include such elements in
any level.
1 | list.clean(.data, fun = is.null, recursive = FALSE)
|
.data |
A |
fun |
A |
recursive |
|
Raw data is usually not completely ready for analysis, and needs to
be cleaned up to certain standards. For example, some data operations
require that the input does not include NULL
values in any
level, therefore fun = "is.null"
and recursive = TRUE
can be useful to clean out all NULL
values in a list at any
level.
Sometimes, not only NULL
values are undesired,
empty vectors or lists are also unwanted. In this case,
fun = function(x) length(x) == 0L
can be useful to remove
all empty elements of zero length. This works because
length(NULL) == 0L
, length(list()) == 0L
and
length(numeric()) == 0L
are all TRUE
.
1 2 3 4 | x <- list(a=NULL,b=list(x=NULL,y=character()),d=1,e=2)
list.clean(x)
list.clean(x, recursive = TRUE)
list.clean(x, function(x) length(x) == 0L, TRUE)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.