Search code examples
rgoogle-scholar

R package "scholar" / getting the citation history of an article


I have a problem with the R package scholar

What works:

get_citation_history(SSalzberg)

What doesn't:

get_article_cite_history(SSalzberg, "any article")

Code:

article <- "Ultrafast and memory-efficient alignment of short DNA sequences to the human genome"
SSalzberg <- "sUVeH-4AAAAJ" (Google Scholar ID)
get_article_cite_history(SSalzberg, article)

Error Message:

Error in min(years):max(years) : result would be too long a vector
In addition: Warning messages:
1: In min(years) : no non-missing arguments to min; returning Inf
2: In max(years) : no non-missing arguments to max; returning -Inf

I do not understand the error message in the context of that function and I tried another paper with an another author without success. I don't know what I am missing here.... Thanks


Solution

  • You have to use an article ID, not the title of the article. Probably the easiest way to get this is to retrieve the full list of pubs, which has a pubid column ...

    library(scholar)
    SSalzberg <- "sUVeH-4AAAAJ"
    all_pubs <- get_publications(SSalzberg)
    ## next step is cosmetic -- the equivalent of stringsAsFactors=FALSE
    all_pubs <- as.data.frame(lapply(all_pubs,
             function(x) if (is.factor(x)) as.character(x) else x))
    w <-grep("Ultrafast",all_pubs$title) ## publication number 3
    all_pubs$title[w]
    ## [1] Ultrafast and memory-efficient alignment of ...
    all_pubs$pubid[w] ## "Tyk-4Ss8FVUC"
    ch <- get_article_cite_history(SSalzberg,all_pubs$pubid[w])
    plot(cites~year,ch,type="b")