dami82 / easyPubMed

easyPubMed package for R - dev version
21 stars 8 forks source link

get_pubmed_id with a My Bibliography page rather than search terms #14

Closed ssmithm closed 1 year ago

ssmithm commented 1 year ago

First, great package Damiano.

I've looked through the vignettes and code and do not see an obvious way to supply a specific URL, e.g., using a persons "My Bibliography" link, rather than supplying search terms, for the get_pubmed_id function. It's easy enough to alter the code to allow a URL (and check whether pubmed_query_string is a URL) -- see below -- but the function then fails at the Data Processing step. I think the issue is that the XML on the end of a PubMed/Entrez search is different when using search terms versus accessing the My Bibliography link directly. Perhaps you've already considered this issue and have a fix, but if not, would you consider adding this functionality?

  myQuery <- as.character(pubmed_query_string)

  if (!is_url(myQuery)) {
    myQuery <- gsub(" ", "+", myQuery, fixed = TRUE)
    myPubmedURL <- paste("https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?",
                         "db=pubmed&term=", myQuery, "&usehistory=y", sep = "")
    if (!is.null(api_key)) {
      myPubmedURL <- paste(myPubmedURL, "&api_key=", api_key, sep = "")
    }
  } else {
    myPubmedURL <- myQuery
  }

where the is_url() function could be as simple as:

is_url <- function(path) {
  grepl("^(http|ftp)s?://", path)
}
dami82 commented 1 year ago

Thanks for the suggestion. To be honest, I have not really considered that possibility before.

The approach you propose makes sense (checking if the query string is a URL or a string... that part is sound). However, I am not sure if a PubMed link like 'my Bibliography" can work with the Eutils API. Let me remind you that easyPubMed is not a web scraper, but is an interface to the Entrez Eutils server. The Eutils API may or may not support data retrieval via a URL that is likely meant to be accessed via a browser. THis has to be tested.

Can you provide an example of a URL that you may want to use?

dami82 commented 1 year ago

I am closing cause I have not received additional feedback/input about this.