r-lib / httr

httr: a friendly http package for R
https://httr.r-lib.org
Other
988 stars 1.99k forks source link

`httr::content` gives different default than `jsonlite::fromJSON` #699

Closed muschellij2 closed 3 years ago

muschellij2 commented 3 years ago

httr::content gives different default than jsonlite::fromJSON as seen below as httr::content uses simplifyVector = FALSE by default as per https://github.com/r-lib/httr/blob/80cb625117629105874d58a234f061b458eefbe6/R/content-parse.r#L75.

res = httr::GET("https://discovery.googleapis.com/discovery/v1/apis")
x = httr::content(res, encoding = "UTF-8")
class(x$items)
#> [1] "list"

x = httr::content(res, 
                  simplifyVector = TRUE)
class(x$items)
#> [1] "data.frame"

x = jsonlite::fromJSON(
  httr::content(res, as = "text"))
class(x$items)
#> [1] "data.frame"

Created on 2021-08-31 by the reprex package (v2.0.0)

Session info ``` r sessioninfo::session_info() #> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R version 4.1.0 (2021-05-18) #> os Debian GNU/Linux 10 (buster) #> system x86_64, linux-gnu #> ui X11 #> language (EN) #> collate C.UTF-8 #> ctype C.UTF-8 #> tz Etc/UTC #> date 2021-08-31 #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date lib source #> cli 3.0.1 2021-07-17 [1] CRAN (R 4.1.0) #> curl 4.3.2 2021-06-23 [1] CRAN (R 4.1.0) #> digest 0.6.27 2020-10-24 [2] CRAN (R 4.1.0) #> evaluate 0.14 2019-05-28 [2] CRAN (R 4.1.0) #> fs 1.5.0 2020-07-31 [2] CRAN (R 4.1.0) #> glue 1.4.2 2020-08-27 [2] CRAN (R 4.1.0) #> highr 0.9 2021-04-16 [2] CRAN (R 4.1.0) #> htmltools 0.5.1.1 2021-01-22 [2] CRAN (R 4.1.0) #> httr 1.4.2 2020-07-20 [2] CRAN (R 4.1.0) #> jsonlite 1.7.2 2020-12-09 [2] CRAN (R 4.1.0) #> knitr 1.33 2021-04-24 [2] CRAN (R 4.1.0) #> magrittr 2.0.1 2020-11-17 [2] CRAN (R 4.1.0) #> R6 2.5.1 2021-08-19 [1] CRAN (R 4.1.0) #> reprex 2.0.0 2021-04-02 [2] CRAN (R 4.1.0) #> rlang 0.4.11 2021-04-30 [2] CRAN (R 4.1.0) #> rmarkdown 2.9 2021-06-15 [2] CRAN (R 4.1.0) #> rstudioapi 0.13 2020-11-12 [2] CRAN (R 4.1.0) #> sessioninfo 1.1.1 2018-11-05 [2] CRAN (R 4.1.0) #> stringi 1.7.3 2021-07-16 [1] CRAN (R 4.1.0) #> stringr 1.4.0 2019-02-10 [2] CRAN (R 4.1.0) #> withr 2.4.2 2021-04-18 [2] CRAN (R 4.1.0) #> xfun 0.24 2021-06-15 [2] CRAN (R 4.1.0) #> yaml 2.2.1 2020-02-01 [2] CRAN (R 4.1.0) #> #> [1] /home/jupyter/.R/library #> [2] /usr/local/lib/R/site-library #> [3] /usr/lib/R/site-library #> [4] /usr/lib/R/library ```
muschellij2 commented 3 years ago

"Fixed" by updating the docs via https://github.com/r-lib/httr/pull/698

persep commented 2 years ago

It's not in the docs anymore in github/master content.Rd branch or in CRAN's version 1.4.4.

Shouldn't it be easier to just leave the default to TRUE like in jsonlite:fromJSON ?