muschellij2 / rscopus

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

extra `/` in `article_retrieval` and `abstract_retrieval` URLs #2

Closed dhicks closed 7 years ago

dhicks commented 7 years ago

The functions article_retrieval and abstract_retrieval add an extra / to the URLs they generate.

Ex:

library(rscopus)
doi = '10.1109/TASE.2014.2368997'
set_api_key('put a real API key here')
abstract_retrieval(doi, identifier = 'doi')

Message output:

HTTP specified is:http://api.elsevier.com/content/article//doi/10.1109/TASE.2014.2368997

Scopus returns a service error for this. I haven't checked whether this happens for other article identifiers, but looking at the code it seems to be generic.

In both functions, the problem is an interaction between the line

ender = paste0("/", paste(identifier, id, sep = "/"))

which prepends one /, and the fact that, in generic_elsevier_api, the large switch statement for search_type returns NULL when type == 'abstract' or 'article'. Then the line

http = paste(root_http, type, search_type, sep = "/")

is equivalent to

http = paste('http://api.elsevier.com/content', 'abstract', NULL, sep = '/')

which returns 'http://api.elsevier.com/content/abstract/'.

I see two potential fixes.

  1. In abstract_retrieval and article_retrieval, replace the problem line with something like

    ender = paste(identifier, id, sep = '/')

    which no longer prepends one '/'.

  2. In generic_elsevier_api, use stringr::str_c in place of paste. https://cran.r-project.org/web/packages/stringr/index.html. This function ignores 0-length strings, including nulls. Ex:

    stringr::str_c('http://api.elsevier.com/content', 'abstract', NULL, sep = '/')

    returns

    "http://api.elsevier.com/content/abstract"
muschellij2 commented 7 years ago

I am trying to maintain this, but I'm not always that active, but fixed this bug in 24c1d19e226bc55a7b564bec0a87f2e87bc040b7 commit. Please retry