-
Notifications
You must be signed in to change notification settings - Fork 0
/
citations.R
47 lines (40 loc) · 990 Bytes
/
citations.R
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
## Helpers
source("utilities.R")
## Be polite
options(openalexR.mailto = "[email protected]")
## Get works
doi <- read.csv(file.path("data", "doi.csv"))
doi$doi <- sprintf("https://doi.org/%s", doi$doi)
works <- try(openalexR::oa_fetch(
entity = "works",
doi = doi$doi,
verbose = TRUE
))
## Get citations
if (!fail(works)) {
works <- merge(x = doi, y = works, by = "doi", all.x = FALSE, all.y = TRUE)
works <- split(works, f = works$package)
cites <- lapply(
X = works,
FUN = function(x) {
oa <- try(openalexR::oa_fetch(
entity = "works",
cites = x$id,
verbose = TRUE
))
if (fail(oa)) return(NULL)
self <- oa$doi %in% doi$doi
oa <- oa[!self, , drop = FALSE]
if (nrow(oa) == 0) return(NULL)
oa
}
)
}
## Write yaml
cites <- Filter(f = Negate(fail), x = cites)
cat(
yaml::as.yaml(cites, column.major = FALSE),
file = file.path("data", "citations.yml"),
sep = "\n",
append = FALSE
)