-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpublications.qmd
More file actions
131 lines (110 loc) · 3.45 KB
/
publications.qmd
File metadata and controls
131 lines (110 loc) · 3.45 KB
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
129
130
131
---
title: "Publications"
author: ""
date: ""
categories: ""
---
```{r}
#| echo: false
#| warning: false
# libraries
library(bibtex)
library(DT)
library(knitr)
# read in biblio
bib <- read.bib('~/../CV/Gregory.bib')
# get citations
o <- unlist(lapply(bib, function(v) paste0(capture.output(v), collapse = ' ')))
# ensure acsii
o <- iconv(o, 'utf-8', 'ascii', sub = '')
# rid of a few things
o <- gsub('In: |pp. ', '', o)
# get authors
foo <- lapply(bib, function(v) v$author)
a <- vector('list', length = length(foo))
for (i in 1:length(foo)) {
fii <- as.character(foo[[i]])
if (length(fii) != 1) {
if (length(foo[[i]]) > 4) {
fii <- paste0(c(fii[1:3], 'et al.'), collapse = ', ')
} else {
fee <- paste0(fii[1:(length(fii) - 1)], collapse = ', ')
fii <- paste0(fee, ' & ', rev(fii)[1])
}
}
a[[i]] <- fii
}
# replace authors in o
o_ <- sapply(o, function(v) gsub('^(.*) (\\([0-9]{4}\\)\\. .*$)', '\\2', v))
o <- paste(a, o_)
# get year
y <- as.numeric(unlist(lapply(bib, function(v) v$year)))
# get DOI
## extract them
d <- lapply(bib, function(v) v$doi)
## add doi.org
d <- unlist(lapply(d, function(v) ifelse(is.null(v), '', paste0('https://doi.org/', v))))
## clean them
d <- gsub('\\.$', '', d)
## convert to html link
d <- ifelse(d == '',
'',
paste0("<a href='", d, "' target = '_blank'>link</a>"))
# get pdfs
## get file names from bib
p <- paste0(names(bib), ".pdf")
## get full file names from Literature
p_fls <- list.files(path = 'C:/Users/SG14/Literature/',
pattern = paste0(unlist(p), collapse = '|'),
full.names = TRUE)
## copy them to pubs_static
pubs_static <- 'C:/Users/SG14/Website/stephendavidgregory.github.io/reprints/'
invisible(file.copy(p_fls, pubs_static, overwrite = TRUE))
# pdf links
## find entries with pdf
p_l <- vector('character', length = length(p))
## index of files
idx <- match(p, gsub("C:/Users/SG14/Literature/", "", p_fls))
## add file locations
p_locs <- ifelse(is.na(idx), '', p_fls[idx])
## add links
for (i in 1:length(p)) {
if (p_locs[i] != "") {
p_l[i] <- paste0('<a href="/reprints/', p[i], '" target="_blank">pdf</a>')
} else {
p_l[i] <- ""
}
}
# remove stuff from citations
o <- gsub("\"", "", o)
# md to html markup
o <- sub("_", "<i>", o)
o <- sub("_", "</i>", o)
o <- sub("\\*", "<b>", o)
o <- sub("\\*", "</b>", o)
# make publications data.frame
pubs_df <- data.frame('citation' = o,
'year' = y,
'doi' = d,
'pdf' = p_l)
# remove an entries without year, e.g., in prep
pubs_df <- subset(pubs_df, !is.na(year))
# order it
pubs_df <- pubs_df[with(pubs_df, order(-year, citation)), ]
# reset row names
rownames(pubs_df) <- 1:nrow(pubs_df)
# make datatable
pubs_dt <- datatable(pubs_df,
width = "100%",
height = "auto",
escape = FALSE,
extensions = list(Scroller = NULL, FixedColumns = list(leftColumns = 2)),
options = list(pageLength = 10,
lengthMenu = c(5, 10, 15, 20, nrow(pubs_df)),
dom = 'T<"clear">lfrtip',
autoWidth = FALSE,
columnDefs = list(list(width = '10%', targets = c(2, 3, 4))),
scrollX = FALSE, scrollY = FALSE, scrollCollapse = TRUE))
# print it
knit_print(x = pubs_dt)
```