muschellij2 / rscopus

Scopus Database API Interface to R
74 stars 16 forks source link

Exporting query results to bibtex #20

Closed zackbatist closed 5 years ago

zackbatist commented 5 years ago

Sorry to pester you with a feature request, but it would be fantastic if there could be built-in functionality that makes it easier to generate bibtex files based on the query results. My experience using R is somewhat limited, and I'm having trouble looping through the results and the entries of those results, to generate bibtex files containing records for each entry resulting from a given query. Any help with this would be very appreciated!

muschellij2 commented 5 years ago

I'm open to accepting a pull request if you want to implement it.

If not, I will get to it maybe around 3-4 months. Does Scopus provide Bibtex outputs? Please indicate which API https://dev.elsevier.com/sc_apis.html and which endpoint https://dev.elsevier.com/api_docs.html provide that. What query are you using that are giving you results? Maybe also look at the raw JSON

muschellij2 commented 5 years ago

Also look at https://media.readthedocs.org/pdf/scopus/latest/scopus.pdf

muschellij2 commented 5 years ago

Looked at their code and adapted. Try bibtex_core_data after installing new rscopus from github.

See example

library(rscopus)
x = abstract_retrieval("S1053811915002700", identifier = "pii",
                       verbose = FALSE)
res2 = bibtex_core_data(x)
cat(res2)
#> @article{Muschelli2015Validatedimages,
#> author = {John Muschelli and Natalie L. Ullman and W. Andrew Mould and Paul Vespa and Daniel F. Hanley and Ciprian M. Crainiceanu},
#> title = {Validated automatic brain extraction of head CT images},
#> journal = {NeuroImage},
#> year = {2015},
#> volume = {114},
#> number = {},
#> pages = {379-385},
#> doi = {10.1016/j.neuroimage.2015.03.074}}

Created on 2019-02-28 by the reprex package (v0.2.1)

zackbatist commented 5 years ago

Thank you so much! Will try it out once it gets pushed to github.

muschellij2 commented 5 years ago

Pushed.

CorradoLanera commented 4 years ago

I encounter some problem here:

library(rscopus)
api_key = get_api_key(NULL, error = FALSE)
if (!is.null(api_key)){
    x = abstract_retrieval("S1053811915002700", identifier = "pii",
                           verbose = FALSE)
    res = bibtex_core_data(x)
    cat(res)
    x = abstract_retrieval("S1053811915002700", identifier = "pii",
                           verbose = FALSE)
    res2 = bibtex_core_data(x)
    cat(res2)
}
#> @article{}@article{}

Created on 2019-12-28 by the reprex package (v0.3.0)

Session info ``` r devtools::session_info() #> - Session info --------------------------------------------------------------- #> setting value #> version R version 3.6.2 (2019-12-12) #> os Windows 10 x64 #> system x86_64, mingw32 #> ui RTerm #> language (EN) #> collate English_United States.1252 #> ctype English_United States.1252 #> tz Europe/Berlin #> date 2019-12-28 #> #> - Packages ------------------------------------------------------------------- #> package * version date lib source #> assertthat 0.2.1 2019-03-21 [1] CRAN (R 3.6.0) #> backports 1.1.5 2019-10-02 [1] CRAN (R 3.6.1) #> callr 3.4.0 2019-12-09 [1] CRAN (R 3.6.1) #> cli 2.0.0.9000 2019-12-21 [1] Github (r-lib/cli@0293ae7) #> crayon 1.3.4 2017-09-16 [1] CRAN (R 3.6.0) #> curl 4.3 2019-12-02 [1] CRAN (R 3.6.1) #> desc 1.2.0 2018-05-01 [1] CRAN (R 3.6.0) #> devtools 2.2.1 2019-09-24 [1] CRAN (R 3.6.1) #> digest 0.6.23 2019-11-23 [1] CRAN (R 3.6.1) #> dplyr 0.8.3 2019-07-04 [1] CRAN (R 3.6.1) #> ellipsis 0.3.0 2019-09-20 [1] CRAN (R 3.6.1) #> evaluate 0.14 2019-05-28 [1] CRAN (R 3.6.0) #> fansi 0.4.0 2018-10-05 [1] CRAN (R 3.6.0) #> fs 1.3.1 2019-05-06 [1] CRAN (R 3.6.0) #> glue 1.3.1 2019-03-12 [1] CRAN (R 3.6.0) #> highr 0.8 2019-03-20 [1] CRAN (R 3.6.0) #> htmltools 0.4.0 2019-10-04 [1] CRAN (R 3.6.1) #> httr 1.4.1 2019-08-05 [1] CRAN (R 3.6.1) #> jsonlite 1.6 2018-12-07 [1] CRAN (R 3.6.0) #> knitr 1.26 2019-11-12 [1] CRAN (R 3.6.1) #> lifecycle 0.1.0 2019-08-01 [1] CRAN (R 3.6.1) #> magrittr 1.5 2014-11-22 [1] CRAN (R 3.6.0) #> memoise 1.1.0 2017-04-21 [1] CRAN (R 3.6.0) #> pillar 1.4.3 2019-12-20 [1] CRAN (R 3.6.2) #> pkgbuild 1.0.6 2019-10-09 [1] CRAN (R 3.6.1) #> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 3.6.1) #> pkgload 1.0.2 2018-10-29 [1] CRAN (R 3.6.0) #> plyr 1.8.5 2019-12-10 [1] CRAN (R 3.6.1) #> prettyunits 1.0.2 2015-07-13 [1] CRAN (R 3.6.0) #> processx 3.4.1 2019-07-18 [1] CRAN (R 3.6.1) #> ps 1.3.0 2018-12-21 [1] CRAN (R 3.6.0) #> purrr 0.3.3 2019-10-18 [1] CRAN (R 3.6.1) #> R6 2.4.1 2019-11-12 [1] CRAN (R 3.6.1) #> Rcpp 1.0.3 2019-11-08 [1] CRAN (R 3.6.1) #> remotes 2.1.0 2019-06-24 [1] CRAN (R 3.6.0) #> rlang 0.4.2 2019-11-23 [1] CRAN (R 3.6.1) #> rmarkdown 2.0 2019-12-12 [1] CRAN (R 3.6.1) #> rprojroot 1.3-2 2018-01-03 [1] CRAN (R 3.6.0) #> rscopus * 0.6.6 2019-09-17 [1] CRAN (R 3.6.1) #> sessioninfo 1.1.1 2018-11-05 [1] CRAN (R 3.6.0) #> stringi 1.4.3 2019-03-12 [1] CRAN (R 3.6.0) #> stringr 1.4.0 2019-02-10 [1] CRAN (R 3.6.0) #> testthat 2.3.1 2019-12-01 [1] CRAN (R 3.6.1) #> tibble 2.1.3 2019-06-06 [1] CRAN (R 3.6.0) #> tidyr 1.0.0 2019-09-11 [1] CRAN (R 3.6.1) #> tidyselect 0.2.5 2018-10-11 [1] CRAN (R 3.6.0) #> usethis 1.5.1.9000 2019-12-21 [1] local #> vctrs 0.2.1 2019-12-17 [1] CRAN (R 3.6.2) #> withr 2.1.2 2018-03-15 [1] CRAN (R 3.6.0) #> xfun 0.11 2019-11-12 [1] CRAN (R 3.6.1) #> yaml 2.2.0 2018-07-25 [1] CRAN (R 3.6.0) #> zeallot 0.1.0 2018-01-28 [1] CRAN (R 3.6.0) #> #> [1] C:/Users/corra/Documents/R/win-library/3.6 #> [2] C:/Program Files/R/R-3.6.2/library ```
muschellij2 commented 4 years ago

Are you sure you're on the necessary IP?

What is the output of

res = rscopus::elsevier_authenticate()
res$auth_type

If this is "GUEST", then the bibtex_core_data may not work.

muschellij2 commented 4 years ago

Try updated GitHub package:

remotes::install_github("muschellij2/rscopus")

The issue is that if you're a guest, the authors data is not there:

library(rscopus)
x = abstract_retrieval("S1053811915002700", identifier = "pii",
                       verbose = FALSE)
res2 = bibtex_core_data(x)
#> Warning in bibtex_core_data(x): Most likely not fully authenticated, see
#> rscopus::elsevier_authenticate() to make sure not GUEST
cat(res2)
#> @article{Muschelli2015Validatedimages,
#> author = {},
#> address = {Johns Hopkins Bloomberg School of Public Health; David Geffen School of Medicine at UCLA; Johns Hopkins Medical Institutions},
#> title = {Validated automatic brain extraction of head CT images},
#> journal = {NeuroImage},
#> year = {2015},
#> volume = {114},
#> number = {},
#> pages = {379-385},
#> doi = {10.1016/j.neuroimage.2015.03.074}
#> abstract = {}}

Created on 2019-12-30 by the reprex package (v0.3.0.9000)

CorradoLanera commented 4 years ago

Are you sure you're on the necessary IP?

What is the output of

res = rscopus::elsevier_authenticate()
res$auth_type

If this is "GUEST", then the bibtex_core_data may not work.

No, I didn't :-). Now, everything works well!