-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Failing Tests for print.tbl_json #99
Comments
I'm not familiar with this package, but I wonder why |
Oh yes, the JSON data is stored in a list at json <- '{"first": "frodo", "title": "hobbit"}'
tj <- as.tbl_json(json)
print(tj)
#> # A tbl_json: 1 x 1 tibble with a "JSON" attribute
#> `attr(., "JSON")` document.id
#> <chr> <int>
#> 1 "{\"first\":\"frodo..." 1
print(attr(tj,'JSON'))
#> [[1]]
#> [[1]]$first
#> [1] "frodo"
#>
#> [[1]]$title
#> [1] "hobbit" The issue I opened with library(tidyjson)
json <- "{\"first\": \"frodo\", \"title\": \"hobbit\"}"
tj <- as.tbl_json(json)
print(tj)
#> # A tbl_json: 1 x 1 tibble with a "JSON" attribute
#> `attr(., "JSON")` document.id
#> <chr> <int>
#> 1 {"first":"frodo... 1
## Using the package
tj %>% spread_all()
#> # A tbl_json: 1 x 3 tibble with a "JSON" attribute
#> `attr(., "JSON")` document.id first title
#> <chr> <int> <chr> <chr>
#> 1 {"first":"frodo... 1 frodo hobbit
tj %>% gather_object %>% append_values_string
#> # A tbl_json: 2 x 3 tibble with a "JSON" attribute
#> `attr(., "JSON")` document.id name string
#> <chr> <int> <chr> <chr>
#> 1 "frodo" 1 first frodo
#> 2 "hobbit" 1 title hobbit |
Maybe define a simple |
Ahh interesting - that makes sense. So I expect that would override the |
I guess so. With the upcoming colformat you could even add color. |
Wow. Very nice. I will explore - much appreciated! I like that solution better than parsing the output of |
@krlmlr Any thoughts/direction on the proposed implementation? I read through
I attempted defining a method for
Parsing the
|
Would you like to document the steps that were needed to create custom output for a tibble column in a tibble vignette? |
Note that you also need `[.json_str` <- function(x, ...) { structure(NextMethod(), class = "json_str") } But even then the tibble formatting routine will reformat your data (even if you wrap it in a list), and this was the main point of your post. We'll need to find a better way here, sorry I led you to the wrong path. The new colformat is a way towards it, but it might take some time to implement. I'm happy to add an experimental S3 method (subject to change) for formatting a column, or to review a PR that adds one. Eventually this method may move to the colformat package, or colformat may be integrated into tibble. Users of tidyjson will see escaped output in the CRAN version but better output in the development versions. Thanks for your input. |
My pleasure, and thank you for your input as well! That is quite helpful direction - I will take a look and see if/how I am able to help. I am happy to contribute a vignette to describe the functionality as well. It sounds like a very promising feature for tibble to be extensible in this way. |
@krlmlr Pretty naive implementation on this branch. I attempted to use The implementation is explored and some pain points are mentioned in the colformat vignette. Not sure whether there is anything worth opening as an issue / enhancement request to ensure that the thoughts are retained. Would be interested to hear your feedback! Thanks. |
At present, tests are failing for print.tbl_json due to tidyverse/tibble#259 since the new
tibble
release, I presume.The text was updated successfully, but these errors were encountered: