forked from agbarnett/helping.funders
-
Notifications
You must be signed in to change notification settings - Fork 0
/
report.Rmd
180 lines (174 loc) · 7.03 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
---
title: "List of papers from ORCID"
author: App created by Adrian Barnett ([email protected])
date: "`r format(Sys.time(), '%d %B %Y')`"
fontsize: 12pt
output: word_document
params:
orcid.id: NA
years.since: NA
spacer: NA
journal.only: NA
order: NA
max.authors: NA
style: 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=T){
res = data.frame(NULL)
res = orcid.input$papers
# bold author
authors = orcid.input$authors
if(bold.author==T){
for (k in 1:nrow(authors)){
authors[k,orcid.input$author.order[k]] = paste('**', authors[k,orcid.input$author.order[k]], '**', sep='') # add bolding
}
}
# 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'}
star.to.use = "\\+ " # how to highlight Open Access papers
results = my.orcid(params$orcid.id)
cat('Publication report for ',results$name,'.\n', sep='')
cat(' \n') # line break
cat('Earliest year of papers =', params$years.since, '.\n', sep='')
papers.sorted = 'ascending year'
if(params$order=='dyear'){papers.sorted = 'descending year'}
if(params$order=='journal'){papers.sorted = 'journal name'}
cat('Papers sorted by ', papers.sorted, '.\n', sep='')
if(params$journal.only=='Yes'){cat('Journals only.\n', sep='')}
if(params$flag.OA==TRUE&results$oa.warning==FALSE){cat("Open Access publications highlighted using a '+' at the start of the reference.\n", sep='')}
if(params$flag.OA==TRUE&results$oa.warning==TRUE){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)
# ARC - different ordering
if(params$style == '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, books$Authors[k], ", ", books$Year[k], ", '", books$Title[k], "', *", 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, journals$Authors[k], ", ", journals$Year[k], ", '", journals$Title[k], "', *", 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, conferences$Authors[k], ", ", conferences$Year[k], ", '", conferences$Title[k], "', *", conferences$Journal[k], '*', sep='')
# add doi if not null
if(is.na(conferences$DOI[k])==F){cat(', doi:', 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, other$Authors[k], ", ", other$Year[k], ", '", other$Title[k], "', *", other$Journal[k], '*', sep='')
# add doi if not null
if(is.na(other$DOI[k])==F){cat(', doi:', other$DOI[k], sep='')}
cat(' \n', sep='') # line break
}
}
} # end of ARC if
# Harvard/APA
if(params$style != 'ARC'){
for (k in 1:nrow(papers)){
star = ""
if(papers$OA[k]==TRUE & params$flag.OA==TRUE){star = star.to.use} # star open access
if(params$style == 'Harvard'){
cat('- ', star, papers$Authors[k], ", ", papers$Year[k], ", '", papers$Title[k], "', *", papers$Journal[k], '*', sep='')
# add volume/issue/doi if not null
if(is.na(papers$Volume[k])==F){cat(', vol. ', papers$Volume[k], sep='')}
if(is.na(papers$Issue[k])==F){cat(', no. ', papers$Issue[k], sep='')}
if(is.na(papers$Pages[k])==F){
pages = papers$Pages[k]
pages = gsub('--', '-', pages) # try to get en dash?
cat(', pp. ', pages, sep='')
}
if(is.na(papers$DOI[k])==F){cat(', doi:', papers$DOI[k], sep='')}
} # end of Harvard
if(params$style == 'APA'){
cat('- ', star, papers$Authors[k], " (", papers$Year[k], "). ", papers$Title[k], '. *', papers$Journal[k], '*', sep='')
# add volume/issue/doi if not null
if(is.na(papers$Volume[k])==F){cat(', **', papers$Volume[k], '**', sep='')}
if(is.na(papers$Pages[k])==F){
pages = papers$Pages[k]
pages = gsub('--', '-', pages) # try to get en dash?
cat(', ', pages, sep='')
}
if(is.na(papers$DOI[k])==F){cat(' doi:', papers$DOI[k], sep='')}
} # end of APA
cat(' \n') # line break
} # end of for loop
} # end of not ARC if
```