ropensci / openalexR

Getting bibliographic records from OpenAlex
https://docs.ropensci.org/openalexR/
Other
91 stars 20 forks source link

error with oa2df when exporting to dataframe/tibble using oa_fetch #157

Closed collinschwantes closed 1 year ago

collinschwantes commented 1 year ago

Recently noticed certain works are throwing errors when using oa_fetch and the convenient export to tibble feature provided by oa2df.

The error I'm getting is: Error in (function (..., deparse.level = 1, make.row.names = TRUE, stringsAsFactors = FALSE, : invalid list argument: all variables should have the same length

Here is an example item that causes the function to break.

# throws the above error
doi <-"https://doi.org/10.4018/978-1-5225-0553-2.ch002" 
ma_works_doi <- openalexR::oa_fetch(entity = "works", doi = doi)

# read in as list and then try to convert

doi <-"https://doi.org/10.4018/978-1-5225-0553-2.ch002" 
ma_works_doi <- openalexR::oa_fetch(entity = "works", doi = doi)

ma_works_doi_list <- openalexR::oa_fetch(entity = "works", doi = doi,output = "list")

openalexR::oa2df(ma_works_doi_list,entity = "works")

Here are several other items that throw the same error.

[
  {
    "doi": "https://doi.org/10.4018/978-1-5225-0553-2.ch002",
    "id": "https://openalex.org/W2476958259",
    "title": "Global Environmental Change and Emerging Infectious Diseases"
  },
  {
    "doi": "https://doi.org/10.4018/978-1-5225-6915-2.ch003",
    "id": "https://openalex.org/W4211260752",
    "title": "Global Environmental Change and Emerging Infectious Diseases"
  },
  {
    "doi": "https://doi.org/10.1016/j.marpolbul.2011.08.041",
    "id": "https://openalex.org/W2140093714",
    "title": "Corrigendum to ‘Baseline heavy metals and metalloid values in blood of loggerhead turtles (Caretta caretta) from Baja California Sur, Mexico’ [Mar. Pollut. Bull. 62 (2011) 1979–1983]"
  },
  {
    "doi": "https://doi.org/10.1101/2021.12.29.474445",
    "id": "https://openalex.org/W4206259884",
    "title": "Nipah virus detection at bat roosts following spillover events in Bangladesh, 2012-2019"
  },
  {
    "doi": "https://doi.org/10.4018/978-1-5225-5487-5.ch021",
    "id": "https://openalex.org/W4211234144",
    "title": "Global Environmental Change and Emerging Infectious Diseases"
  },
  {
    "doi": "https://doi.org/10.1101/2022.09.29.22280519",
    "id": "https://openalex.org/W4297963711",
    "title": "Global patterns and correlates in the emergence of antimicrobial resistance in humans"
  }
] 

Session Info

R version 4.2.1 (2022-06-23)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS Big Sur 11.7.8

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

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

other attached packages:
[1] openalexR_1.2.0

loaded via a namespace (and not attached):
 [1] fansi_1.0.4       prettyunits_1.1.1 utf8_1.2.3        conflicted_1.2.0  crayon_1.5.2     
 [6] R6_2.5.1          lifecycle_1.0.3   jsonlite_1.8.4    magrittr_2.0.3    pillar_1.9.0     
[11] httr_1.4.5        rlang_1.1.0       cachem_1.0.7      progress_1.2.2    cli_3.6.1        
[16] renv_1.0.0        curl_5.0.0        rstudioapi_0.14   vctrs_0.6.1       tools_4.2.1      
[21] glue_1.6.2        hms_1.1.3         yaml_2.3.7        fastmap_1.1.1     compiler_4.2.1   
[26] pkgconfig_2.0.3   memoise_2.0.1     tibble_3.2.1 
yjunechoe commented 1 year ago

Thanks for the report! This looks like the same issue raised in #154 and #156.

The dev version should have the fix for your error. Can you try running the code again with:

# install.packages("remotes")
remotes::install_github("ropensci/openalexR")
collinschwantes commented 1 year ago

Ran with dev, no items threw errors. Thanks!