You can install the development version of from GitHub with:
# install.packages("remotes")
remotes::install_github("rappster/drop")
Drop, i.e. remove, certain values in (nested) list structures.
Experimental and scope is “scratch your own itch”.
Because I always seem to need it at some point in various other projects and always struggled to find/remember previous implementations that worked.
By leveraging rrapply (see SO post)
library(drop)
x <- list(
foo = NULL,
bar = 1,
baz = TRUE,
foobar = "a"
)
x %>% drop_null()
#> $bar
#> [1] 1
#>
#> $baz
#> [1] TRUE
#>
#> $foobar
#> [1] "a"
x <- list(
list(foo = NULL, bar = 1)
)
x %>% drop_null()
#> [[1]]
#> [[1]]$bar
#> [1] 1
x <- list(
foo = list(bar = NULL, baz = list(x = 1, y = NULL, z = 3)),
baz = 2
)
x %>% drop_null()
#> $foo
#> $foo$baz
#> $foo$baz$x
#> [1] 1
#>
#> $foo$baz$z
#> [1] 3
#>
#>
#>
#> $baz
#> [1] 2
Empty input is simply returned
list() %>% drop_null()
#> list()
x <- list(
foo = integer(),
bar = 1,
baz = TRUE,
foobar = "a"
)
x %>% drop_empty()
#> $bar
#> [1] 1
#>
#> $baz
#> [1] TRUE
#>
#> $foobar
#> [1] "a"
x <- list(
list(
foo = character(), bar = 1)
)
x %>% drop_empty()
#> [[1]]
#> [[1]]$bar
#> [1] 1
x <- list(
foo = list(bar = logical(), baz = list(x = 1, y = numeric(), z = 3)),
baz = 2
)
x %>% drop_empty()
#> $foo
#> $foo$baz
#> $foo$baz$x
#> [1] 1
#>
#> $foo$baz$z
#> [1] 3
#>
#>
#>
#> $baz
#> [1] 2
Empty input is simply returned
list() %>% drop_empty()
#> list()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.