-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathreport.Rmd
241 lines (227 loc) · 9.29 KB
/
report.Rmd
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
---
title: "List of papers from ORCID"
author: App created by Adrian Barnett (a.barnett@qut.edu.au)
date: "`r format(Sys.time(), '%d %B %Y')`"
fontsize: 12pt
output: word_document
params:
orcid.id: NA
orcid.file:
input: NA
value: NA
years.since: NA
spacer: NA
journal.only: NA
order: NA
max.authors: NA
style: NA
bullets: NA
extra.order: NA
flag.OA: NA
bold.author: NA
---
```{r setup, include=FALSE}
# TO DO, make a function to clean pages for multiple formats
# TO DO, ARC style - not finished
knitr::opts_chunk$set(echo = FALSE, warnings=FALSE, comment='')
# function to get filtered papers
my.filter = function(orcid.input, years.since=2000, max.authors=3, spacer=', ', journal.only='Yes', order='ayear', bold.author=TRUE){
res = data.frame(NULL)
res = orcid.input$papers
# bold author
authors = orcid.input$authors
if(bold.author==TRUE){
for (k in 1:nrow(authors)){
if(orcid.input$author.order[k] <= ncol(authors)){ # only bold if author order is in range (March 2022)
authors[k, orcid.input$author.order[k]] = paste('**', authors[k, orcid.input$author.order[k]], '**', sep='') # add bold
}
}
}
# add authors
if(max.authors == 1){res$Authors = authors[,1]}
if(max.authors > 1){
upper.limit = min(c(max.authors, ncol(authors)))
res$Authors = apply(authors[, 1:upper.limit], 1, paste5, collapse=spacer) #
}
# add 'et al'
if(max.authors < ncol(orcid.input$authors)){ # don't add if at max author number
index = orcid.input$authors[, max.authors+1] != '' # something in next author
res$Authors[index] = paste(res$Authors[index], spacer, 'et al', sep='')
}
# filter by year:
res = subset(res, Year >= years.since)
# journal articles only
if(journal.only=='Yes'){
index = grep(pattern='journal', tolower(res$Type)) # search for journal in type
res = res[index, ]
}
## ordering (this part comes from server)
papers = res
papers$Year = as.numeric(papers$Year) # for sorting
if(order=='ayear'){papers = arrange(papers, Year)} #
if(order=='dyear'){papers = arrange(papers, -Year)} #
if(order=='journal'){papers = arrange(papers, Journal, Year)} #
papers$Year = as.character(papers$Year) # looks better as character
## return
return(papers)
}
```
```{r list.papers, results='asis'}
# bullets (turning words into TRUE/FALSE)
use.bullets = FALSE
if(params$bullets=='bullets'){use.bullets = TRUE}
# how to highlight Open Access papers:
star.to.use = "\\+ "
# single or multiple ORCID ids?
inFile = params$orcid.file
if(is.null(inFile) == TRUE){results = my.orcid(params$orcid.id)} # single
if(is.null(inFile) == FALSE){ # multiple
multiple.orcids = read.table(inFile$datapath, header=FALSE, stringsAsFactors=FALSE) # get the ORCIDs from the file
n.people = nrow(multiple.orcids)
# Loop through people
results = list()
results$papers = results$authors = results$auth.order = results$name = results$oa.warning= NULL
for (k in 1:n.people){
id.no.spaces = multiple.orcids$V1[k]
id.no.spaces = id.no.spaces[id.no.spaces!=''] # remove missing IDs
id.no.spaces = gsub(' $', '', id.no.spaces) # remove trailing space
o = my.orcid(orcid.id = id.no.spaces)
# concatenate
results$papers = rbind(results$papers, o$papers)
results$authors = rbind(results$authors, o$authors)
results$auth.order = c(results$auth.order, o$auth.order)
results$name = c(results$name, o$name)
results$oa.warning = c(results$oa.warning, o$oa.warning)
} # end of people loop
}
# blurb at top
if(is.null(inFile) == TRUE){cat('Publication report for ', str_squish(results$name), '.\n', sep='')} # single
if(is.null(inFile) == FALSE){cat('Combined publication report for ', paste(results$name, collapse=', '), '.\n', sep='')} # multiple
cat(' \n') # line break
cat('Earliest year of papers =', params$years.since, '.\n', sep='')
papers.sorted = 'bottom'
if(params$order=='dyear'){papers.sorted = 'top'}
if(params$order=='journal'){papers.sorted = 'journal name'}
cat('Most recent papers at ', papers.sorted, '.\n', sep='')
if(params$journal.only=='Yes'){cat('Journals only.\n', sep='')}
if(params$flag.OA==TRUE & sum(results$oa.warning)==0){cat("Open Access publications highlighted using a '+' at the start of the reference.\n", sep='')}
if(params$flag.OA==TRUE & sum(results$oa.warning) > 0){cat("Open Access data did not load; try again.\n", sep='')}
cat(' \n') # line break
papers = my.filter(results, max.authors=params$max.authors, order=params$order,
journal.only=params$journal.only, years.since=params$years.since,
spacer=params$spacer, bold.author = params$bold.author)
# no extra ordering
if(params$extra.order == 'None'){
to.display = display.papers(papers, in.style=params$style, star.to.use=star.to.use, flag.OA=params$flag.OA, bullets=use.bullets)
cat(to.display)
}
# ARC - different ordering
if(params$extra.order == 'ARC'){
## sort by output type
counter = 0
# a) books
index = grep('book', tolower(papers$Type))
if(length(index)>0){
cat('## Books\n', sep='\n')
books = papers[index,]
for (k in 1:nrow(books)){
star = ""
if(books$OA[k]==TRUE & params$flag.OA==TRUE){star = star.to.use} # star open access
counter = counter + 1
cat(counter, '. ', star,
str_squish(books$Authors[k]), ", ",
str_squish(books$Year[k]), ", '",
str_squish(books$Title[k]), "', *",
str_squish(books$Journal[k]), '*', sep='')
# add doi if not null
if(is.na(books$DOI[k])==F){cat(', doi:', books$DOI[k], sep='')}
}
}
# b) journal articles
index = grep('journal', tolower(papers$Type))
if(length(index)>0){
cat('## Journal articles\n', sep='\n')
journals = papers[index,]
for (k in 1:nrow(journals)){
star = ""
if(journals$OA[k]==TRUE & params$flag.OA==TRUE){star = star.to.use} # star open access
counter = counter + 1
cat(counter, '. ', star,
str_squish(journals$Authors[k]), ", ",
str_squish(journals$Year[k]), ", '",
str_squish(journals$Title[k]), "', *",
str_squish(journals$Journal[k]), '*', sep='')
# add doi if not null
if(is.na(journals$DOI[k])==F){cat(', doi:', journals$DOI[k], sep='')}
cat(' \n', sep='') # line break
}
}
# c) conferences
index = grep('conference', tolower(papers$Type))
if(length(index)>0){
cat('## Journal articles\n', sep='\n')
conferences = conferences[index,]
for (k in 1:nrow(conferences)){
star = ""
if(conferences$OA[k]==TRUE & params$flag.OA==TRUE){star = star.to.use} # star open access
counter = counter + 1
cat(counter, '. ', star,
str_squish(conferences$Authors[k]), ", ",
str_squish(conferences$Year[k]), ", '",
str_squish(conferences$Title[k]), "', *",
str_squish(conferences$Journal[k]), '*', sep='')
# add doi if not null
if(is.na(conferences$DOI[k])==F){cat(', doi:', str_squish(conferences$DOI[k]), sep='')}
cat(' \n', sep='') # line break
}
}
# d) other
index = grep('conference|journal|book', tolower(papers$Type), invert = T)
if(length(index)>0){
cat('## Other\n', sep='\n')
other = papers[index,]
for (k in 1:nrow(other)){
star = ""
if(other$OA[k]==TRUE & params$flag.OA==TRUE){star = star.to.use} # star open access
counter = counter + 1
cat(counter, '. ', star,
str_squish(other$Authors[k]), ", ",
str_squish(other$Year[k]), ", '",
str_squish(other$Title[k]), "', *",
str_squish(other$Journal[k]), '*', sep='')
# add doi if not null
if(is.na(other$DOI[k])==F){cat(', doi:', str_squish(other$DOI[k]), sep='')}
cat(' \n', sep='') # line break
}
}
} # end of ARC if
# split by author order - different ordering
if(params$extra.order == 'split'){
# a) First author
if(sum(papers$First.author) > 0){
cat('## First author\n', sep='\n')
this = dplyr::filter(papers, First.author==1)
to.display = display.papers(this, in.style=params$style, star.to.use=star.to.use, flag.OA=params$flag.OA, bullets=use.bullets)
cat(to.display)
cat('\n\n')
counter = nrow(this) # for numbers instead of bullets
}
# b) Last author
if(sum(papers$Last.author) > 0){
cat('## Last author\n', sep='\n')
this = dplyr::filter(papers, Last.author==1)
to.display = display.papers(this, in.style=params$style, star.to.use=star.to.use, flag.OA=params$flag.OA, bullets=use.bullets, counter.start=counter)
cat(to.display)
cat('\n\n')
counter = counter + nrow(this) # for numbers instead of bullets
}
# c) Neither first nor last author
this = dplyr::filter(papers, Last.author==0 & First.author==0)
if(nrow(this) > 0){
cat('## Neither first nor last author\n', sep='\n')
to.display = display.papers(this, in.style=params$style, star.to.use=star.to.use, flag.OA=params$flag.OA, bullets=use.bullets, counter.start=counter)
cat(to.display)
cat('\n')
}
} # end of `split` if
```