Title: | Tidy up nested list hairballs |
---|---|
Description: | This is a package to transform large, multi-nested lists into a more user-friendly format. The initial focus is on making processing of return values from `jsonlite::fromJSON()` queries more seamless, but ideally this package should be useful for deeply-nested lists from an array of sources. |
Authors: | Amanda Dobbyn [aut], Christine Stawitz [aut], Isabella Velasquez [aut], Jim Hester [aut, cre], Laura DeCicco [aut] |
Maintainer: | Jim Hester <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.0 |
Built: | 2024-11-02 02:42:26 UTC |
Source: | https://github.com/cstawitz/roomba |
Package: | roomba |
Type: | Package |
Collection of functions to do deal with deeply nested data
Perform a recursive depth first search of a function
dfs_idx(.x, .f)
dfs_idx(.x, .f)
.x |
A list or atomic vector. |
.f |
A function, formula, or atomic vector. If a function, it is used as is. If a formula, e.g.
This syntax allows you to create very compact anonymous functions. If character vector, numeric vector, or list, it
is converted to an extractor function. Character vectors index by name
and numeric vectors index by position; use a list to index by position
and name at different levels. Within a list, wrap strings in |
List all names in a list
list_names(x)
list_names(x)
x |
list to use |
Example data from reddit
An object of class list
of length 2.
https://www.reddit.com/dev/api/
Replace all the empty values in a list
replace_null(x, replacement = NA)
replace_null(x, replacement = NA)
x |
list to use |
replacement |
Replacement value for missing values |
list(a = NULL, b = 1, c = list(foo = NULL, bar = NULL)) %>% replace_null()
list(a = NULL, b = 1, c = list(foo = NULL, bar = NULL)) %>% replace_null()
Tidy your nested list
roomba(inp, cols = NULL, default = NA, keep = all)
roomba(inp, cols = NULL, default = NA, keep = all)
inp |
List to tidy |
cols |
Columns to keep |
default |
Replacement for NULL values. Defaults to NA. |
keep |
Should all or any data be kept? |
simple %>% roomba(cols = c("name", "goodstuff"), keep = any) simple %>% roomba(cols = c("name", "goodstuff"), keep = any)
simple %>% roomba(cols = c("name", "goodstuff"), keep = any) simple %>% roomba(cols = c("name", "goodstuff"), keep = any)
Run the roomba app
shiny_roomba(browse = TRUE)
shiny_roomba(browse = TRUE)
browse |
Logical. Use browser for running Shiny app. |
## Not run: if(require(shiny)){ shiny_roomba() } ## End(Not run)
## Not run: if(require(shiny)){ shiny_roomba() } ## End(Not run)
Example data with simple nested list
simple
simple
An object of class character
of length 1.
Example data from Twitter API
twitter_data
twitter_data
An object of class list
of length 20.
twitter_data[[1]][["id"]]
[[1]: R:[1 ["id"]: R:
https://developer.twitter.com/en/docs
Example data from vimeo
vimeo
vimeo
An object of class response
of length 10.