append_values | R Documentation |
The append_values
functions let you take any scalar JSON values
of a given type ("string", "number", "logical") and add them as a new
column named column.name
. This is particularly useful after using
gather_object
to gather an object.
append_values_string(.x, column.name = type, force = TRUE, recursive = FALSE) append_values_number(.x, column.name = type, force = TRUE, recursive = FALSE) append_values_logical(.x, column.name = type, force = TRUE, recursive = FALSE)
.x |
a json string or |
column.name |
the name of the column to append values as |
force |
should values be coerced to the appropriate type when possible, otherwise, types are checked first (requires more memory) |
recursive |
logical indicating whether to recurisvely extract a single
value from a nested object. Only used when |
Any values that can not be converted to the specified will be NA
in
the resulting column. This includes other scalar types (e.g., numbers or
logicals if you are using append_values_string
) and *also* any rows
where the JSON is NULL or an object or array.
Note that the append_values
functions do not alter the JSON
attribute of the tbl_json
object in any way.
a tbl_json
object
gather_object
to gather an object first,
spread_all
to spread values into new columns,
json_get_column
# Stack names '{"first": "bob", "last": "jones"}' %>% gather_object %>% append_values_string # This is most useful when data is stored in name-value pairs # For example, tags in recipes: recipes <- c('{"name": "pie", "tags": {"apple": 10, "pie": 2, "flour": 5}}', '{"name": "cookie", "tags": {"chocolate": 2, "cookie": 1}}') recipes %>% spread_values(name = jstring(name)) %>% enter_object(tags) %>% gather_object("tag") %>% append_values_number("count")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.