-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathserver.R
More file actions
361 lines (312 loc) · 13.6 KB
/
server.R
File metadata and controls
361 lines (312 loc) · 13.6 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
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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
library(shiny)
library(knitr)
# Define server
shinyServer(function(input, output) {
#source("helper.r")
# Set seed
set.seed(sample(1:10000, 1))
# Read in cleaned up words and part of speech / sentiment
words <- read.csv("joe_words.csv")
words$word <- tolower(words$word)
# Put everything into lowercase
adjective <- tolower(words$word[which(words$pos == "adjective")])
verb <- tolower(words$word[which(words$pos == "verb")])
noun <- tolower(words$word[which(words$pos == "noun")])
# Write function to get words by type
joe <- function(pos, sentiment = NULL, reg = NULL, neg_reg = NULL, number = 1){
x <- words
if(!is.null(sentiment)){
x <- x[which(x$pos == pos & x$sentiment == sentiment),]
}
if(!is.null(reg)){
x <- x[which(grepl(reg, x$word)),]
}
if(!is.null(neg_reg)){
x <- x[which(!grepl(neg_reg, x$word)),]
}
x <- x$word[which(x$pos == pos)]
if(length(x) > 0){
return(sample(x, number))
} else{
return(sample(words$word[which(words$pos == pos & words$sentiment == sentiment)], 1))
}
}
# Write generate paper function
GeneratePaper <- function(title,
author,
to,
sentiment,
journal){
############
line1 <- paste0("Dear ", to, ",")
############
l2nega <- paste0("It was with a great deal of ",
joe("noun", "negative"),
" that I read ",
author,
"'s most ",
joe("adjective", "negative"),
" article entitled '",
title, "'.")
l2negb <- paste0("I was very ",
joe(pos = "adjective", sentiment = "negative", reg = "ed", neg_reg = "need"),
" to read ",
author,
"'s most ",
joe("adjective", "negative"),
" article entitled '",
title, "'.")
l2negc <- paste0(author,
"'s ",
"most ",
joe(pos = "adjective", sentiment = "negative"),
" article ('",
title,
"')",
" was a perfect example of everything that is ",
joe("adjective", "negative"),
" and ",
joe("adjective", "negative"),
" with the field of epidemiology today.")
l2posa <- paste0(author,
"'s '",
title,
"' was a most ",
joe("adjective", "positive", reg = "ous", neg_reg = "famous"), " break from the typical ",
joe("noun", "negative"),
" that our field usually produces these days.")
l2posb <- paste0("I was absolutely ",
joe("adjective", "positive"),
" upon reading ",
author,
"'s most ",
joe("adjective", "positive"),
" article entitled '",
title,
"'.")
l2posc <- paste0(author,
"'s ",
joe("adjective", "positive"),
" '",
title,
"' was a complete ",
joe("noun", "positive", neg_reg = "ion"),
", especially when compared to the usual ",
joe("noun", "negative"),
" published by this journal",
".")
if(sentiment == "negative"){
line2 <- sample(c(l2nega, l2negb, l2negc), 1)
} else{
line2 <- sample(c(l2posa, l2posb, l2posc), 1)
}
############
l3nega <- paste0("It is rare to come across such a ",
joe("adjective", "negative"),
" example of ",
joe("noun", "negative"),
" filled with so many ",
joe("noun", "negative", neg_reg = "ness"),
"s.")
l3negb <- paste0("In my many years of reading ",
journal,
", this is the first time I've found myself so ",
joe("adjective", "negative", reg = "*ed", neg_reg = "ly"),
" by an article that I felt compelled to write.")
l3negc <- paste0("Even by the standards of ",
journal,
", this article was noteworthy for being both ",
joe("adjective", "negative"),
" and ",
joe("adjective", "negative"),
", a rare combination indeed.")
l3posa <- paste0("What a joy it was to read such a fine example of ",
joe("noun", "positive", "inte"),
" and ",
joe("noun", "positive"),
", a rare combination in today's increasingly ",
joe("adjective", "negative", neg_reg="ly"),
" field.")
l3posb <- paste0("Few studies so ",
joe("adjective", "positive", "succ", neg_reg = "ly"),
"ly combine such ",
joe("adjective", "positive", reg = NULL, neg_reg = "ly"),
" design with ",
joe("adjective", "positive"),
" analytical approaches.")
l3posc <- paste0("I have never come across a finer example of ",
joe("adjective", "positive"),
" methods and ",
joe("adjective", "positive"),
" writing, and I ",
joe("verb", "positive"),
" the authors for ",
joe("verb", "positive"),
"ing in such ",
joe("adjective", "positive"),
" ways. ")
if(sentiment == "negative"){
line3 <- sample(c(l3nega, l3negb, l3negc), 1)
} else{
line3 <- sample(c(l3posa, l3posb, l3posc), 1)
}
############
l4negasub1 <- paste0("The authors lack any and all ",
joe("adjective", "positive"),
" evidence for their secondary findings. ")
l4negasub2 <- paste0("The authors' methods are both ",
joe("adjective", "negative"),
" and ",
joe("adjective", "negative", "ed"),
". ")
l4negasub3 <- paste0("The authors' insistence on the ",
joe("noun", "positive", "ence"),
" of their findings ignore nearly a decade of ",
joe("adjective", "positive", neg_reg = "ly"),
" work in an increasingly ",
joe("adjective", "positive"),
" field. ")
l4negasub4 <- paste0("The authors' conclusions are not only unsupported by their (",
joe("adjective", "negative"),
") data, but they also appear to contradict it ",
joe("adjective", "negative", neg_reg = "ly"),
"ly. ")
l4nega <- paste0("The article's shortcomings are three-fold: 1) ",
l4negasub1, " 2) ",
l4negasub2, " 3) ",
l4negasub3)
l4negb <- paste0("The article has two ",
joe("adjective", "negative"),
" shortcomings: 1) ",
l4negasub4, " 2) ",
l4negasub2)
l4posasub4 <- paste0("the authors' ",
joe("adjective", "positive", neg_reg = "ly"),
" analysis and ",
joe("adjective", "positive", neg_reg = "ly"),
" interpretation of their results more than adequately compensate ",
"for the ",
joe("noun", "negative", "ence"),
" of their study design. ")
l4posa <- paste0(l4negasub3,
" That said, ",
l4posasub4)
l4posb <- paste0("The authors'",
joe("adjective", "positive", neg_reg = "ly"),
" analysis and ",
joe("adjective", "positive", neg_reg = "ly"),
" interpretation of their results more than adequately compensate ",
"for the ",
joe("noun", "negative", "ence"),
" of their study design. That said, it is worth pointing out ",
"2 noteworthy problems: ",
"1) ",
l4negasub4,
" 2) ",
l4negasub3,
" These criticsms should not detract from ",
author,
"'s ",
"overall message (which I found to be ",
joe("adjective", "positive"),
") or the article's ",
joe("noun", "positive", "est"),
". ")
if(sentiment == "negative"){
line4 <- sample(c(l4nega, l4negb), 1)
} else{
line4 <- sample(c(l4posa, l4posb), 1)
}
############
l5nega <- paste0("I sincerely hope that ",
author,
" will reconsider their conclusions, and that in the future ",
journal,
" will be a bit more careful in selecting articles they deem ",
joe("adjective", "positive"),
" enough for publication. ")
l5negb <- paste0("Though this article contains elements of ",
joe("adjective", "positive", neg_reg = "ly"),
" insight, ",
author,
" muddled their message with ",
joe("adjective", "negative", neg_reg = "ly"),
"ly ",
joe("adjective", "negative"),
" analyses of otherwise ",
joe("adjective", "positive"),
" data. ")
l5negc <- paste0("I encourage ",
author,
" to withdraw their paper from publication, given the ",
joe("adjective", "negative"),
" flaws in the design, analysis and interpretation of",
" what otherwise could have been a ",
joe("adjective", "positive"),
" contribution to our field. ")
l5negd <- paste0("J'accuse ",
author,
" of ",
joe("adjective", "negative"), " ",
joe("noun", "negative", "ism"),
" and implore ",
journal,
" to withdraw this article's publication entirely. ")
l5posa <- paste0("I applaud ",
author,
" for their ",
joe("adjective", "positive"),
" contribution to our field, ",
" and encourage others to follow their example. ")
l5posb <- paste0(author,
"'s study represents a ",
joe("adjective", "positive"),
" and ",
joe("adjective", "positive"),
" shift in the way epidemiologists ",
joe("verb", "positive", "ize"),
" our understanding of ",
joe("noun", "positive", "ism"),
". ")
l5posc <- paste0(author,
"'s most serious shortcoming was that they did not fully ",
joe("verb", "positive", "ize"),
" the ",
joe("noun", "positive", "ance"),
" of their findings. ")
l5posd <- paste0("'",
title,
"'",
" deserves widespread dissemination for its ",
joe("verb", "positive", neg_reg = "ly"),
"ly ",
joe("adjective", "positive"),
" implications for future studies of the population in question. ")
l5pos1 <- sample(c(l5posb, l5posc), 1)
l5pos2 <- sample(c(l5posa, l5posd), 1)
l5neg1 <- l5negb
l5neg2 <- sample(c(l5nega, l5negc, l5negd), 1)
if(sentiment == "negative"){
line5 <- paste0(l5neg1, l5neg2)
} else{
line5 <- paste0(l5pos1, l5pos2)
}
x <- list(line1, line2, line3, line4, line5)
return(x)
}
output$downloadPDF <-
downloadHandler(filename = "report.pdf",
content = function(file){
# generate PDF
knit2pdf("report.Rnw")
# copy pdf to 'file'
file.copy("report.pdf", file)
# delete generated files
file.remove("report.pdf", "report.tex",
"report.aux", "report.log")
# delete folder with plots
unlink("figure", recursive = TRUE)
},
contentType = "application/pdf"
)
})