-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpublications.qmd
129 lines (120 loc) · 4.16 KB
/
publications.qmd
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# Publications
## Books
- <span class="author_publication">Burn E</span>, Black A, Raventós B, <span class="author_publication">Guo Y</span>, <span class="author_publication">Du M</span>, <span class="author_publication">López-Güell K</span>, <span class="author_publication">Mercadé-Besora N</span>, <span class="author_publication">Català M</span>. *Tidy-R-programming-with-OMOP* (**2024**). <https://github.com/oxford-pharmacoepi/Tidy-R-programming-with-OMOP>
## Articles
```{r, results='hide', message=FALSE, echo=FALSE}
authors <- c(
"burn, edward", "catala, marti", "newby, danielle", "du, mike",
"burkard, theresa", "lopez guell, kim", "spivakovsky gonzalez, pablo",
"alcalde herraiz, marta", "mercade besora, nuria"
)
x <- pubmedR::pmApiRequest(
paste0(authors, "[Author]", collapse = " OR "), limit = Inf)
authors <- c(authors, "guo, yuchen", "chen, xihang")
getIds <- function(xx) {
res <- list(pubmed = NA_character_, doi = NA_character_)
dat <- xx$PubmedData$ArticleIdList
for (i in seq_along(dat)) {
nm <- dat[[i]]$.attrs |> unname()
val <- dat[[i]]$text
if (nm %in% c("pubmed", "doi")) {
if (nm == "doi") val <- paste0("https://doi.org/", val)
res[[nm]] <- val
}
}
return(res)
}
getDate <- function(xx) {
dat <- xx$MedlineCitation$Article$ArticleDate
x <- as.Date(paste0(dat$Year, "-", dat$Month, "-", dat$Day), format = "%Y-%m-%d")
if (is.na(x)) {
dat <- xx$PubmedData$History$PubMedPubDate
x <- as.Date(paste0(dat$Year, "-", dat$Month, "-", dat$Day), format = "%Y-%m-%d")
}
return(x)
}
cleanName <- function(y) {
y |>
stringr::str_to_lower() |>
stringr::str_split(pattern = ",| |-") |>
lapply(dplyr::first) |>
unlist() |>
stringr::str_replace(pattern = "à", replacement = "a") |>
stringr::str_replace(pattern = "á", replacement = "a") |>
stringr::str_replace(pattern = "è", replacement = "e") |>
stringr::str_replace(pattern = "é", replacement = "e") |>
stringr::str_replace(pattern = "í", replacement = "i") |>
stringr::str_replace(pattern = "ó", replacement = "o") |>
stringr::str_replace(pattern = "ò", replacement = "o") |>
stringr::str_replace(pattern = "ú", replacement = "u") |>
stringr::str_replace(pattern = "ü", replacement = "u")
}
ours <- list()
ours$last_name <- authors |>
stringr::str_split(pattern = ", ") |>
lapply(dplyr::first) |>
lapply(cleanName) |>
unlist()
ours$fore_name <- authors |>
stringr::str_split(pattern = ", ") |>
lapply(dplyr::nth, 2) |>
lapply(cleanName) |>
unlist()
ours <- dplyr::as_tibble(ours)
getAuthor <- function(xx, ours) {
ids <- rep(0, nrow(ours))
auts <- xx$MedlineCitation$Article$AuthorList
aut <- character()
for (i in seq_along(auts)) {
au <- auts[[i]]
if (all(c("LastName", "ForeName") %in% names(au))) {
a <- paste(au$LastName, au$Initials)
ln <- cleanName(au$LastName)
fn <- cleanName(au$ForeName)
if (ln %in% ours$last_name & fn %in% ours$fore_name) {
ids[ours$last_name == ln & ours$fore_name == fn] <- 1
a <- paste0('<span class="author_publication">', a, '</span>')
}
aut[i] <- a
}
}
aut <- paste0(aut, collapse = ", ")
return(list(aut = aut, ids = ids))
}
data <- NULL
for (k in seq_along(x$data)) {
xx <- x$data[[k]]
ids <- getIds(xx)
aut <- getAuthor(xx, ours)
nms <- aut$ids |>
as.list() |>
rlang::set_names(ours$last_name)
data <- data |>
dplyr::union_all(dplyr::tibble(
id = k,
article = xx$MedlineCitation$Article$ArticleTitle |>
stringr::str_flatten(),
date = getDate(xx),
pubmed = as.numeric(ids$pubmed),
doi = ids$doi,
journal = xx$MedlineCitation$Article$Journal$Title,
authors = aut$aut,
!!!nms
))
}
data <- data |>
dplyr::mutate(
year = clock::get_year(date),
cite = paste0(
"- ", authors, ". ", article, " (**", year, "**), *", journal, "*. <", doi,
">"
)
) |>
dplyr::arrange(dplyr::desc(date))
data <- data |>
dplyr::mutate(sum = dplyr::select(data, dplyr::all_of(ours$last_name)) |> rowSums(na.rm = TRUE))
text <- paste0(data$cite, collapse = "\n")
```
```{r, results='asis', echo=FALSE}
cat(text)
```