-
Notifications
You must be signed in to change notification settings - Fork 11
/
README.Rmd
159 lines (114 loc) · 3.67 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
---
output: github_document
---
```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# roomba <img src="img/sticker.png" alt="roomba_gif" height="150px" align="right" />
[![Travis build status](https://travis-ci.com/ropenscilabs/roomba.svg?branch=master)](https://travis-ci.com/ropenscilabs/roomba)
This is a package to transform large, multi-nested lists into a more user-friendly format (i.e. a `tibble`) in `R`. 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.
<!-- ![roomba_gif](https://media.giphy.com/media/mwMowfcaEcvpm/giphy.gif) -->
<p align="center">
<img src="https://media.giphy.com/media/mP9hvHDhy4E9i/giphy.gif" alt="roomba_gif">
</p>
*Key features:*
* `roomba()` searches deeply-nested list for names specified in `cols` (a character vector) and returns a `tibble` with the associated column titles. Nothing further about nesting hierarchy or depth need be specified.
* Handles empty values gracefully by substituting `NULL` values with `NA` or user-specified value in `default`, or truncates lists appropriately.
* If you're only interested in sniffing out and replacing all `NULL`s, turn to the `replace_null()` function.
* Option to `keep` `any` or `all` data from the columns supplied
## Installation
You can install the development version from [GitHub](https://github.com/) with:
```{r, eval=FALSE}
# install.packages("devtools")
devtools::install_github("cstawitz/roomba")
```
## Usage
Say we have some JSON from a pesky API.
```{r example, message=FALSE}
library(roomba)
json <- '
{
"stuff": {
"buried": {
"deep": [
{
"location": "here",
"name": "Laura DeCicco",
"super_power": "fixing merge conflicts",
"other_secret_power": []
},
{
"location": "here",
"name": "Amanda Dobbyn",
"super_power": "flight",
"more_nested_stuff": 4
}
],
"alsodeep": 2342423234,
"stilldeep": {
"even_deeper": [
{
"location": "not here",
"name": "Jim Hester",
"super_power": []
},
{
"location": "here",
"name": "Christine Stawitz",
"super_power": "invisibility",
"more_nested_stuff": 5
},
{
"location": "here",
"name": "Isabella Velasquez",
"super_power": "teleportation"
}
]
}
}
}
}'
```
The JSON becomes a nested R list,
```{r}
super_data <- json %>%
jsonlite::fromJSON(simplifyVector = FALSE)
```
which we can pull data into the columns we want with `roomba`.
```{r}
super_data %>%
roomba(cols = c("name", "super_power", "more_nested_stuff"), keep = any)
```
<br>
Let's try with a real-world Twitter example (see package data to use this data).
```{r}
roomba(twitter_data, c("created_at", "name"))
```
# Shiny app included!
<p align="center">
<img src="images/shinydemo.gif" alt="roomba_gif">
</p>
Run the app like this:
```{r eval=FALSE}
shiny_roomba()
```
<br>
# What did that original data look like???
Feast your eyes on the original `super_data` list!
```{r}
super_data
```
And just the *first* element of the `twitter` dataset `r emo::ji("scream")`
```{r}
twitter_data[[1]]
```
<br>
**Happy cleaning!**
<p align="center">
<img src="https://media.giphy.com/media/mwMowfcaEcvpm/giphy.gif" alt="roomba_gif">
</p>