ropensci / rcrossref

R client for various CrossRef APIs
https://docs.ropensci.org/rcrossref
Other
165 stars 21 forks source link

Issues in accessing CrossRef works in R (problem in caracter encoding (UFT8)) #227

Closed w0lfsoul closed 2 years ago

w0lfsoul commented 2 years ago

I am trying to get a reference from Cross Reference using rcrossref::cr_cn, with the following code

library(rcrossref)
  doi="10.1038/s43017-020-0100-8"
  ref.res <- rcrossref::cr_works(doi)

and I obtain the following error message:

Error in cr_GET(endpoint = path, args, todf = FALSE, ...) : res$response_headers$content-type == "application/json;charset=UTF-8" is not TRUE

I have tried to manually change the encoding: doi=enc2utf8(doi) or doi= stringr::str_conv(doi, "UTF-8") But the result remains the same.

A few more information:

Encoding(doi)
[1] "unknown"

and

Sys.getlocale()
[1] "LC_COLLATE=English_United Kingdom.1252;LC_CTYPE=English_United Kingdom.1252;LC_MONETARY=English_United Kingdom.1252;LC_NUMERIC=C;LC_TIME=English_United Kingdom.1252"

sessionInfo() `R version 4.0.3 (2020-10-10) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 19042)

Matrix products: default

locale: [1] LC_COLLATE=English_United States.1252 [2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_Ireland.1252
[4] LC_NUMERIC=C
[5] LC_TIME=C

attached base packages: [1] stats graphics grDevices datasets utils methods
[7] base

other attached packages: [1] stringi_1.7.6 dplyr_1.0.7 readxl_1.3.1 rcrossref_1.1.0

loaded via a namespace (and not attached): [1] Rcpp_1.0.8 cellranger_1.1.0 plyr_1.8.6
[4] compiler_4.0.3 pillar_1.6.5 later_1.3.0
[7] tools_4.0.3 digest_0.6.29 jsonlite_1.7.3
[10] lifecycle_1.0.1 tibble_3.1.6 pkgconfig_2.0.3
[13] rlang_0.4.12 DBI_1.1.2 shiny_1.7.1
[16] crul_1.2.0 curl_4.3.2 xfun_0.29
[19] fastmap_1.1.0 xml2_1.3.3 stringr_1.4.0
[22] generics_0.1.1 vctrs_0.3.8 htmlwidgets_1.5.4 [25] triebeard_0.3.0 DT_0.20 tidyselect_1.1.1 [28] glue_1.6.0 httpcode_0.3.0 R6_2.5.1
[31] fansi_1.0.2 purrr_0.3.4 magrittr_2.0.1
[34] urltools_1.7.3 promises_1.2.0.1 ellipsis_0.3.2
[37] htmltools_0.5.2 assertthat_0.2.1 mime_0.12
[40] xtable_1.8-4 httpuv_1.6.5 tinytex_0.36
[43] utf8_1.2.2 miniUI_0.1.1.1 crayon_1.4.2
`

Many thanks in advance for you help

ps. I have seen this problem in other posts (eg https://stackoverflow.com/questions/68412035/rcrossref-api-error-resresponse-headerscontent-type-application-jsonch) but they could not solve this issue.

njahn82 commented 2 years ago

Hi, please update the package using the dev version available on GitHub.

remotes::install_github("ropensci/rcrossref")

The dev version fixes issues, which occurred after Crossref's API migration.

rcrossref::cr_works("10.1038/s43017-020-0100-8")
#> $meta
#> NULL
#> 
#> $data
#> # A tibble: 1 × 33
#>   alternative.id container.title             created   deposited published.print
#>   <chr>          <chr>                       <chr>     <chr>     <chr>          
#> 1 100            Nature Reviews Earth & Env… 2020-09-… 2021-09-… 2020-10        
#> # … with 28 more variables: published.online <chr>, doi <chr>, indexed <chr>,
#> #   issn <chr>, issue <chr>, issued <chr>, member <chr>, page <chr>,
#> #   prefix <chr>, publisher <chr>, score <chr>, source <chr>,
#> #   reference.count <chr>, references.count <chr>,
#> #   is.referenced.by.count <chr>, subject <chr>, title <chr>, type <chr>,
#> #   update.policy <chr>, url <chr>, volume <chr>, language <chr>,
#> #   short.container.title <chr>, assertion <list>, author <list>, …
#> 
#> $facets
#> NULL

Created on 2022-01-31 by the reprex package (v2.0.0)

w0lfsoul commented 2 years ago

perfect!!! many thanks

jumattern commented 2 years ago

I unfortunately still get the error, even after updating the package to the dev version on Github:

packageVersion("rcrossref")
[1] ‘1.1.0.99’
rcrossref::cr_works("10.1038/s43017-020-0100-8")
Error in cr_GET(endpoint = path, args, todf = FALSE, ...) : 
  res$response_headers$`content-type` == "application/json;charset=UTF-8" is not TRUE
njahn82 commented 2 years ago

Cannot replicate. Can you share a reprex including session info with me?

rcrossref::cr_works("10.1038/s43017-020-0100-8")
#> $meta
#> NULL
#> 
#> $data
#> # A tibble: 1 × 33
#>   alternative.id container.title             created   deposited published.print
#>   <chr>          <chr>                       <chr>     <chr>     <chr>          
#> 1 100            Nature Reviews Earth & Env… 2020-09-… 2021-09-… 2020-10        
#> # … with 28 more variables: published.online <chr>, doi <chr>, indexed <chr>,
#> #   issn <chr>, issue <chr>, issued <chr>, member <chr>, page <chr>,
#> #   prefix <chr>, publisher <chr>, score <chr>, source <chr>,
#> #   reference.count <chr>, references.count <chr>,
#> #   is.referenced.by.count <chr>, subject <chr>, title <chr>, type <chr>,
#> #   update.policy <chr>, url <chr>, volume <chr>, language <chr>,
#> #   short.container.title <chr>, assertion <list>, author <list>, …
#> 
#> $facets
#> NULL

Created on 2022-02-11 by the reprex package (v2.0.0)

Session info ``` r sessioninfo::session_info() #> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R version 4.1.2 (2021-11-01) #> os macOS Big Sur 11.4 #> system aarch64, darwin20 #> ui X11 #> language en #> collate de_DE.UTF-8 #> ctype de_DE.UTF-8 #> tz Europe/Copenhagen #> date 2022-02-11 #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date lib source #> assertthat 0.2.1 2019-03-21 [1] CRAN (R 4.1.0) #> backports 1.2.1 2020-12-09 [1] CRAN (R 4.1.0) #> cli 3.1.0 2021-10-27 [1] CRAN (R 4.1.1) #> crayon 1.4.2 2021-10-29 [1] CRAN (R 4.1.1) #> crul 1.1.0 2021-02-15 [1] CRAN (R 4.1.0) #> curl 4.3.2 2021-06-23 [1] CRAN (R 4.1.0) #> DBI 1.1.1 2021-01-15 [1] CRAN (R 4.1.0) #> digest 0.6.28 2021-09-23 [1] CRAN (R 4.1.1) #> dplyr 1.0.7 2021-06-18 [1] CRAN (R 4.1.0) #> DT 0.19 2021-09-02 [1] CRAN (R 4.1.1) #> ellipsis 0.3.2 2021-04-29 [1] CRAN (R 4.1.0) #> evaluate 0.14 2019-05-28 [1] CRAN (R 4.1.0) #> fansi 0.5.0 2021-05-25 [1] CRAN (R 4.1.0) #> fastmap 1.1.0 2021-01-25 [1] CRAN (R 4.1.0) #> fs 1.5.0 2020-07-31 [1] CRAN (R 4.1.0) #> generics 0.1.1 2021-10-25 [1] CRAN (R 4.1.1) #> glue 1.4.2 2020-08-27 [1] CRAN (R 4.1.0) #> highr 0.9 2021-04-16 [1] CRAN (R 4.1.0) #> htmltools 0.5.2 2021-08-25 [1] CRAN (R 4.1.1) #> htmlwidgets 1.5.4 2021-09-08 [1] CRAN (R 4.1.1) #> httpcode 0.3.0 2020-04-10 [1] CRAN (R 4.1.0) #> httpuv 1.6.3 2021-09-09 [1] CRAN (R 4.1.1) #> jsonlite 1.7.2 2020-12-09 [1] CRAN (R 4.1.0) #> knitr 1.37 2021-12-16 [1] CRAN (R 4.1.1) #> later 1.3.0 2021-08-18 [1] CRAN (R 4.1.1) #> lifecycle 1.0.1 2021-09-24 [1] CRAN (R 4.1.1) #> magrittr 2.0.1 2020-11-17 [1] CRAN (R 4.1.0) #> mime 0.12 2021-09-28 [1] CRAN (R 4.1.1) #> miniUI 0.1.1.1 2018-05-18 [1] CRAN (R 4.1.0) #> pillar 1.6.4 2021-10-18 [1] CRAN (R 4.1.0) #> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.1.0) #> plyr 1.8.6 2020-03-03 [1] CRAN (R 4.1.0) #> promises 1.2.0.1 2021-02-11 [1] CRAN (R 4.1.0) #> purrr 0.3.4 2020-04-17 [1] CRAN (R 4.1.0) #> R6 2.5.1 2021-08-19 [1] CRAN (R 4.1.1) #> Rcpp 1.0.7 2021-07-07 [1] CRAN (R 4.1.0) #> rcrossref 1.1.0.99 2021-10-16 [1] Github (ropensci/rcrossref@319f34c) #> reprex 2.0.0 2021-04-02 [1] CRAN (R 4.1.0) #> rlang 0.4.12 2021-10-18 [1] CRAN (R 4.1.0) #> rmarkdown 2.11 2021-09-14 [1] CRAN (R 4.1.1) #> sessioninfo 1.1.1 2018-11-05 [1] CRAN (R 4.1.0) #> shiny 1.7.1 2021-10-02 [1] CRAN (R 4.1.1) #> stringi 1.7.5 2021-10-04 [1] CRAN (R 4.1.1) #> stringr 1.4.0 2019-02-10 [1] CRAN (R 4.1.0) #> styler 1.5.1 2021-07-13 [1] CRAN (R 4.1.0) #> tibble 3.1.5 2021-09-30 [1] CRAN (R 4.1.1) #> tidyselect 1.1.1 2021-04-30 [1] CRAN (R 4.1.0) #> triebeard 0.3.0 2016-08-04 [1] CRAN (R 4.1.0) #> urltools 1.7.3 2019-04-14 [1] CRAN (R 4.1.0) #> utf8 1.2.2 2021-07-24 [1] CRAN (R 4.1.0) #> vctrs 0.3.8 2021-04-29 [1] CRAN (R 4.1.0) #> withr 2.4.3 2021-11-30 [1] CRAN (R 4.1.1) #> xfun 0.29 2021-12-14 [1] CRAN (R 4.1.1) #> xml2 1.3.2 2020-04-23 [1] CRAN (R 4.1.0) #> xtable 1.8-4 2019-04-21 [1] CRAN (R 4.1.0) #> yaml 2.2.1 2020-02-01 [1] CRAN (R 4.1.0) #> #> [1] /Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/library ```
jumattern commented 2 years ago

Sorry for the hassle, problem seem to be resolved now. I guess it was related with the local RSPM/renv config. Works fine now, thank you!

library(rcrossref)
packageVersion("rcrossref")
#> [1] '1.1.0.99'

rcrossref::cr_works("10.1038/s43017-020-0100-8")
#> $meta
#> NULL
#> 
#> $data
#> # A tibble: 1 × 33
#>   alternative.id container.title             created   deposited published.print
#>   <chr>          <chr>                       <chr>     <chr>     <chr>          
#> 1 100            Nature Reviews Earth & Env… 2020-09-… 2021-09-… 2020-10        
#> # … with 28 more variables: published.online <chr>, doi <chr>, indexed <chr>,
#> #   issn <chr>, issue <chr>, issued <chr>, member <chr>, page <chr>,
#> #   prefix <chr>, publisher <chr>, score <chr>, source <chr>,
#> #   reference.count <chr>, references.count <chr>,
#> #   is.referenced.by.count <chr>, subject <chr>, title <chr>, type <chr>,
#> #   update.policy <chr>, url <chr>, volume <chr>, language <chr>,
#> #   short.container.title <chr>, assertion <list>, author <list>, …
#> 
#> $facets
#> NULL
njahn82 commented 2 years ago

No worries, glad it works!

LukasWallrich commented 2 years ago

@njahn82 and team - we would love to use rcrossref to enhance namedropR ... so we were wondering when you are planning to submit these fixes to CRAN?

njahn82 commented 2 years ago

Thanks for the great news. I'll try to make it ready for CRAN in the next two weeks.

nucleic-acid commented 1 year ago

Dear @njahn82 and team, Do you have an updated timeline for the next update?

Sorry to bother you on this one again. CRAN requires us to update the namedropR package and I'd like to include the CrossRef functionality while I update.

If you're not planning to update in the foreseeable future that's okay. I'll just need to move that feature to a future CRAN update then.

njahn82 commented 1 year ago

Sorry @nucleic-acid for the late reply, I am planning to submit the changes to CRAN. You can follow the progress here: https://github.com/ropensci/rcrossref/tree/cran_1.2

njahn82 commented 1 year ago

Hi @nucleic-acid latest rcrossref release is available on CRAN.

nucleic-acid commented 1 year ago

Thanks for the notification! And thanks for the work to get this update into CRAN.