I have a DOI for an article, I am wondering if there are any R functions that can download the pdf file based on this DOI without the user having to download the pdf manually ?
You can use httr
to see where that DOI points to by constructing a URL to doi.org
and getting the headers:
library(httr)
headers = HEAD("http://doi.org/10.7150/ijms.11309")
headers$url
# [1] "http://www.medsci.org/v12p0264.htm"
In this case, the PDF seems to be at the same location as that page, but with a .pdf
extension. But this is not true for all journals.
So for this journal, the PDF is at:
sub(".htm$",".pdf",headers$url)
# [1] "http://www.medsci.org/v12p0264.pdf"
So I can then do:
download.file(sub(".htm$",".pdf",headers$url),"paper.pdf")
to get the PDF.