Open ramiromagno opened 3 years ago
This seems to be working on my side:
enter_object2 <- function (.x, ..., drop.null.json = TRUE) {
if (!tidyjson::is.tbl_json(.x))
.x <- tidyjson::as.tbl_json(.x)
path <- tidyjson:::path(...)
json <- tidyjson::json_get(.x)
json <- purrr::map(json, path %>% as.list)
tidyjson::tbl_json(.x, json, drop.null.json = drop.null.json)
}
It's only a bit risky because I am now depending on the internal function tidyjson:::path(...)
, but it's the only one.
Awesome!! Thanks for reporting this - this is definitely a confusing part of the package. #121 is where we have tracked this in the past, but you have done much more on the topic than anyone previously!
Would you be interested in PRing your function change and adding some tests? I am inclined to feel drop_null_json
would be a better naming convention for the new argument. Alternatively, perhaps drop = TRUE
would be a better default. I.e. looking at tidyr::spread
, it seems that "unexplained" references to the word "drop" can be contextualized by help docs / etc.
What about .drop = TRUE
?
Any progress on this issue? Also, any thoughts on implementing something similar to spread_all()
?
Feature request
From the documentation details about
enter_object()
:Could you give the user the option to not discard?
From the source code of
enter_object
it does not seem difficult to allow this:could it be changed to this code?
Motivation
Perhaps I am not using tidyjson idiomatically, but I would like to use the code below to extract a json array and bind it as a new column. In the example below I have a tbl json with 3 rows: in the third row the object
"associated_pgs_ids"
isnull
. Therefore I cannot take advantage of this functionget_column_char()
becausetidyjson::enter_object
will return only two rows instead of three, not allowing me to further bind this column to the starting tibble.get_column_chr()
Example code