-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDOI2bib_v2.R
More file actions
30 lines (27 loc) · 797 Bytes
/
DOI2bib_v2.R
File metadata and controls
30 lines (27 loc) · 797 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
## 1. input the DOIs, for instance:
DOI <- read.table("....")$DOI
DOI <- scan(what = "") # by hand or copy/paste
## ... or else
## 2. Give a name for the output file:
OUTFILE <- "outfile.bib"
## 3. Run the followings:
baseurl <- "https://dx.doi.org/"
hdr <- "application/x-bibtex"
names(hdr) <- "Accept"
for (doi in DOI) {
theurl <- paste0(baseurl, doi)
URL <- url(theurl, headers = hdr)
o <- try(open(URL))
if (inherits(o, "try-error")) {
cat("==>> Wrong doi =", doi, "<<==\n")
next
}
X <- try(scan(URL, "", sep = "\n"))
close(URL)
if (inherits(X, "try-error")) {
cat("==>> Download failed for doi =", doi, "<<==\n")
next
}
cat(X, sep = "\n", file = OUTFILE, append = TRUE)
cat("\n", file = OUTFILE, append = TRUE)
}