View source: R/spread_values.R
spread_values | R Documentation |
The spread_values
function lets you extract extract specific values
from (potentiall nested) JSON objects. spread_values
takes
jstring
, jnumber
or jlogical
named
function calls as arguments in order to specify the type of the data that
should be captured at each desired name-value pair location. These values can
be of varying types at varying depths.
spread_values(.x, ...)
.x |
a json string or |
... |
|
Note that jstring
, jnumber
and
jlogical
will fail if they encounter the incorrect type in any
document.
The advantage of spread_values
over spread_all
is that
you are guaranteed to get a consistent data frame structure (columns and
types) out of any spread_values
call. spread_all
requires less typing, but because it infers the columns and their types from
the JSON, it is less suitable when programming.
a tbl_json
object
spread_all
for spreading all values,
spread
for spreading data frames,
jstring
, jnumber
,
jlogical
for accessing specific names
# A simple example json <- '{"name": {"first": "Bob", "last": "Jones"}, "age": 32}' # Using spread_values json %>% spread_values( first.name = jstring(name, first), last.name = jstring(name, last), age = jnumber(age) ) # Another document, this time with a middle name (and no age) json2 <- '{"name": {"first": "Ann", "middle": "A", "last": "Smith"}}' # spread_values still gives the same column structure c(json, json2) %>% spread_values( first.name = jstring(name, first), last.name = jstring(name, last), age = jnumber(age) ) # whereas spread_all adds a new column json %>% spread_all c(json, json2) %>% spread_all
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.