-
Notifications
You must be signed in to change notification settings - Fork 1
/
Final Attempt.R
843 lines (662 loc) · 25.7 KB
/
Final Attempt.R
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
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
library(tidyverse)
library(twitteR)
#twitter authentication
setup_twitter_oauth(consumer_key = getOption("twitter_api_key"),
consumer_secret = getOption("twitter_api_token"))
#1
# set the sequence of dates to search over
dates <- seq(as.Date("2015-08-06"), as.Date("2015-8-20"), by = "day") %>%
as.character()
# create a list to store the tweets
tweets <- vector("list", length(dates))
# use a for loop to run the immigration search starting on each date
for(i in seq_along(dates)) {
tweets[[i]] <- searchTwitter('immigrant | immigration & -RT',
n=1000, lang='en',
since= dates[i]) %>%
strip_retweets(strip_manual = TRUE, strip_mt = TRUE) %>%
twListToDF() %>%
tbl_df
}
# collapse tweets into a single data frame
tweets_joined <- bind_rows(tweets) %>%
# remove duplicate tweets that were retrieved in multiple searches
unique()
str(tweets_joined)
#2
# set the sequence of dates to search over
dates2 <- seq(as.Date("2015-08-21"), as.Date("2015-8-31"), by = "day") %>%
as.character()
# create a list to store the tweets
tweets2 <- vector("list", length(dates2))
# use a for loop to run the immigration search starting on each date
for(i in seq_along(dates2)) {
tweets2[[i]] <- searchTwitter('immigrant | immigration & -RT',
n=1000, lang='en',
since= dates2[i]) %>%
strip_retweets(strip_manual = TRUE, strip_mt = TRUE) %>%
twListToDF() %>%
tbl_df
}
# collapse tweets into a single data frame
tweets_joined2 <- bind_rows(tweets2) %>%
# remove duplicate tweets that were retrieved in multiple searches
unique()
str(tweets_joined2)
#3
# set the sequence of dates to search over
dates3 <- seq(as.Date("2015-09-01"), as.Date("2015-9-15"), by = "day") %>%
as.character()
# create a list to store the tweets
tweets3 <- vector("list", length(dates3))
# use a for loop to run the immigration search starting on each date
for(i in seq_along(dates3)) {
tweets3[[i]] <- searchTwitter('immigrant | immigration & -RT',
n=1000, lang='en',
since= dates3[i]) %>%
strip_retweets(strip_manual = TRUE, strip_mt = TRUE) %>%
twListToDF() %>%
tbl_df
}
# collapse tweets into a single data frame
tweets_joined3 <- bind_rows(tweets3) %>%
# remove duplicate tweets that were retrieved in multiple searches
unique()
str(tweets_joined3)
#4
# set the sequence of dates to search over
dates4 <- seq(as.Date("2015-09-16"), as.Date("2015-9-30"), by = "day") %>%
as.character()
# create a list to store the tweets
tweets4 <- vector("list", length(dates4))
# use a for loop to run the immigration search starting on each date
for(i in seq_along(dates4)) {
tweets4[[i]] <- searchTwitter('immigrant | immigration & -RT',
n=1000, lang='en',
since= dates4[i]) %>%
strip_retweets(strip_manual = TRUE, strip_mt = TRUE) %>%
twListToDF() %>%
tbl_df
}
# collapse tweets into a single data frame
tweets_joined4 <- bind_rows(tweets4) %>%
# remove duplicate tweets that were retrieved in multiple searches
unique()
str(tweets_joined4)
#5
# set the sequence of dates to search over
dates5 <- seq(as.Date("2015-10-01"), as.Date("2015-10-15"), by = "day") %>%
as.character()
# create a list to store the tweets
tweets5 <- vector("list", length(dates5))
# use a for loop to run the immigration search starting on each date
for(i in seq_along(dates5)) {
tweets5[[i]] <- searchTwitter('immigrant | immigration & -RT',
n=1000, lang='en',
since= dates5[i]) %>%
strip_retweets(strip_manual = TRUE, strip_mt = TRUE) %>%
twListToDF() %>%
tbl_df
}
# collapse tweets into a single data frame
tweets_joined5 <- bind_rows(tweets5) %>%
# remove duplicate tweets that were retrieved in multiple searches
unique()
str(tweets_joined5)
#6
# set the sequence of dates to search over
dates6 <- seq(as.Date("2015-10-16"), as.Date("2015-10-31"), by = "day") %>%
as.character()
# create a list to store the tweets
tweets6 <- vector("list", length(dates6))
# use a for loop to run the immigration search starting on each date
for(i in seq_along(dates6)) {
tweets6[[i]] <- searchTwitter('immigrant | immigration & -RT',
n=1000, lang='en',
since= dates6[i]) %>%
strip_retweets(strip_manual = TRUE, strip_mt = TRUE) %>%
twListToDF() %>%
tbl_df
}
# collapse tweets into a single data frame
tweets_joined6 <- bind_rows(tweets6) %>%
# remove duplicate tweets that were retrieved in multiple searches
unique()
str(tweets_joined6)
#7
# set the sequence of dates to search over
dates7 <- seq(as.Date("2015-11-01"), as.Date("2015-11-15"), by = "day") %>%
as.character()
# create a list to store the tweets
tweets7 <- vector("list", length(dates7))
# use a for loop to run the immigration search starting on each date
for(i in seq_along(dates7)) {
tweets7[[i]] <- searchTwitter('immigrant | immigration & -RT',
n=1000, lang='en',
since= dates7[i]) %>%
strip_retweets(strip_manual = TRUE, strip_mt = TRUE) %>%
twListToDF() %>%
tbl_df
}
# collapse tweets into a single data frame
tweets_joined7 <- bind_rows(tweets7) %>%
# remove duplicate tweets that were retrieved in multiple searches
unique()
str(tweets_joined7)
#8
# set the sequence of dates to search over
dates8 <- seq(as.Date("2015-11-16"), as.Date("2015-11-30"), by = "day") %>%
as.character()
# create a list to store the tweets
tweets8 <- vector("list", length(dates8))
# use a for loop to run the immigration search starting on each date
for(i in seq_along(dates8)) {
tweets8[[i]] <- searchTwitter('immigrant | immigration & -RT',
n=1000, lang='en',
since= dates8[i]) %>%
strip_retweets(strip_manual = TRUE, strip_mt = TRUE) %>%
twListToDF() %>%
tbl_df
}
# collapse tweets into a single data frame
tweets_joined8 <- bind_rows(tweets8) %>%
# remove duplicate tweets that were retrieved in multiple searches
unique()
str(tweets_joined8)
tweets_til_151130 <- bind_rows(tweets, tweets2, tweets3, tweets4, tweets5, tweets6, tweets7, tweets8)
write_csv(tweets_til_151130, "tweets_til_151130.csv")
#9
# set the sequence of dates to search over
dates9 <- seq(as.Date("2015-12-01"), as.Date("2015-12-15"), by = "day") %>%
as.character()
# create a list to store the tweets
tweets9 <- vector("list", length(dates9))
# use a for loop to run the immigration search starting on each date
for(i in seq_along(dates9)) {
tweets9[[i]] <- searchTwitter('immigrant | immigration & -RT',
n=1000, lang='en',
since= dates9[i]) %>%
strip_retweets(strip_manual = TRUE, strip_mt = TRUE) %>%
twListToDF() %>%
tbl_df
}
# collapse tweets into a single data frame
tweets_joined9 <- bind_rows(tweets9) %>%
# remove duplicate tweets that were retrieved in multiple searches
unique()
str(tweets_joined9)
#10
# set the sequence of dates to search over
dates10 <- seq(as.Date("2015-12-16"), as.Date("2015-12-31"), by = "day") %>%
as.character()
# create a list to store the tweets
tweets10 <- vector("list", length(dates10))
# use a for loop to run the immigration search starting on each date
for(i in seq_along(dates10)) {
tweets10[[i]] <- searchTwitter('immigrant | immigration & -RT',
n=1000, lang='en',
since= dates10[i]) %>%
strip_retweets(strip_manual = TRUE, strip_mt = TRUE) %>%
twListToDF() %>%
tbl_df
}
# collapse tweets into a single data frame
tweets_joined10 <- bind_rows(tweets10) %>%
# remove duplicate tweets that were retrieved in multiple searches
unique()
str(tweets_joined10)
#11
# set the sequence of dates to search over
dates11 <- seq(as.Date("2016-01-01"), as.Date("2016-01-15"), by = "day") %>%
as.character()
# create a list to store the tweets
tweets11 <- vector("list", length(dates11))
# use a for loop to run the immigration search starting on each date
for(i in seq_along(dates11)) {
tweets11[[i]] <- searchTwitter('immigrant | immigration & -RT',
n=1000, lang='en',
since= dates11[i]) %>%
strip_retweets(strip_manual = TRUE, strip_mt = TRUE) %>%
twListToDF() %>%
tbl_df
}
# collapse tweets into a single data frame
tweets_joined11 <- bind_rows(tweets11) %>%
# remove duplicate tweets that were retrieved in multiple searches
unique()
str(tweets_joined11)
#12
# set the sequence of dates to search over
dates12 <- seq(as.Date("2016-01-16"), as.Date("2016-01-31"), by = "day") %>%
as.character()
# create a list to store the tweets
tweets12 <- vector("list", length(dates12))
# use a for loop to run the immigration search starting on each date
for(i in seq_along(dates12)) {
tweets12[[i]] <- searchTwitter('immigrant | immigration & -RT',
n=1000, lang='en',
since= dates12[i]) %>%
strip_retweets(strip_manual = TRUE, strip_mt = TRUE) %>%
twListToDF() %>%
tbl_df
}
# collapse tweets into a single data frame
tweets_joined12 <- bind_rows(tweets12) %>%
# remove duplicate tweets that were retrieved in multiple searches
unique()
str(tweets_joined12)
#13
# set the sequence of dates to search over
dates13 <- seq(as.Date("2016-02-01"), as.Date("2016-02-15"), by = "day") %>%
as.character()
# create a list to store the tweets
tweets13 <- vector("list", length(dates13))
# use a for loop to run the immigration search starting on each date
for(i in seq_along(dates13)) {
tweets13[[i]] <- searchTwitter('immigrant | immigration & -RT',
n=1000, lang='en',
since= dates13[i]) %>%
strip_retweets(strip_manual = TRUE, strip_mt = TRUE) %>%
twListToDF() %>%
tbl_df
}
# collapse tweets into a single data frame
tweets_joined13 <- bind_rows(tweets13) %>%
# remove duplicate tweets that were retrieved in multiple searches
unique()
str(tweets_joined13)
#14
# set the sequence of dates to search over
dates14 <- seq(as.Date("2016-02-16"), as.Date("2016-02-29"), by = "day") %>%
as.character()
# create a list to store the tweets
tweets14 <- vector("list", length(dates14))
# use a for loop to run the immigration search starting on each date
for(i in seq_along(dates14)) {
tweets14[[i]] <- searchTwitter('immigrant | immigration & -RT',
n=1000, lang='en',
since= dates14[i]) %>%
strip_retweets(strip_manual = TRUE, strip_mt = TRUE) %>%
twListToDF() %>%
tbl_df
}
# collapse tweets into a single data frame
tweets_joined14 <- bind_rows(tweets14) %>%
# remove duplicate tweets that were retrieved in multiple searches
unique()
str(tweets_joined14)
#15
# set the sequence of dates to search over
dates15 <- seq(as.Date("2016-03-01"), as.Date("2016-03-15"), by = "day") %>%
as.character()
# create a list to store the tweets
tweets15 <- vector("list", length(dates15))
# use a for loop to run the immigration search starting on each date
for(i in seq_along(dates15)) {
tweets15[[i]] <- searchTwitter('immigrant | immigration & -RT',
n=1000, lang='en',
since= dates15[i]) %>%
strip_retweets(strip_manual = TRUE, strip_mt = TRUE) %>%
twListToDF() %>%
tbl_df
}
# collapse tweets into a single data frame
tweets_joined15 <- bind_rows(tweets15) %>%
# remove duplicate tweets that were retrieved in multiple searches
unique()
str(tweets_joined15)
#16
# set the sequence of dates to search over
dates16 <- seq(as.Date("2016-03-16"), as.Date("2016-03-31"), by = "day") %>%
as.character()
# create a list to store the tweets
tweets16 <- vector("list", length(dates16))
# use a for loop to run the immigration search starting on each date
for(i in seq_along(dates16)) {
tweets16[[i]] <- searchTwitter('immigrant | immigration & -RT',
n=1000, lang='en',
since= dates16[i]) %>%
strip_retweets(strip_manual = TRUE, strip_mt = TRUE) %>%
twListToDF() %>%
tbl_df
}
# collapse tweets into a single data frame
tweets_joined16 <- bind_rows(tweets16) %>%
# remove duplicate tweets that were retrieved in multiple searches
unique()
str(tweets_joined16)
#17
# set the sequence of dates to search over
dates17 <- seq(as.Date("2016-04-01"), as.Date("2016-04-15"), by = "day") %>%
as.character()
# create a list to store the tweets
tweets17 <- vector("list", length(dates17))
# use a for loop to run the immigration search starting on each date
for(i in seq_along(dates17)) {
tweets17[[i]] <- searchTwitter('immigrant | immigration & -RT',
n=1000, lang='en',
since= dates17[i]) %>%
strip_retweets(strip_manual = TRUE, strip_mt = TRUE) %>%
twListToDF() %>%
tbl_df
}
# collapse tweets into a single data frame
tweets_joined17 <- bind_rows(tweets17) %>%
# remove duplicate tweets that were retrieved in multiple searches
unique()
str(tweets_joined17)
tweets_151130_to_160415 <- bind_rows(tweets9, tweets10, tweets11, tweets12, tweets13, tweets14, tweets15, tweets16, tweets17)
write_csv(tweets_151130_to_160415, "tweets_151130_to_160415")
#18
# set the sequence of dates to search over
dates18 <- seq(as.Date("2016-04-16"), as.Date("2016-04-30"), by = "day") %>%
as.character()
# create a list to store the tweets
tweets18 <- vector("list", length(dates18))
# use a for loop to run the immigration search starting on each date
for(i in seq_along(dates18)) {
tweets18[[i]] <- searchTwitter('immigrant | immigration & -RT',
n=1000, lang='en',
since= dates18[i]) %>%
strip_retweets(strip_manual = TRUE, strip_mt = TRUE) %>%
twListToDF() %>%
tbl_df
}
# collapse tweets into a single data frame
tweets_joined18 <- bind_rows(tweets18) %>%
# remove duplicate tweets that were retrieved in multiple searches
unique()
str(tweets_joined18)
#19
# set the sequence of dates to search over
dates19 <- seq(as.Date("2016-05-01"), as.Date("2016-05-15"), by = "day") %>%
as.character()
# create a list to store the tweets
tweets19 <- vector("list", length(dates19))
# use a for loop to run the immigration search starting on each date
for(i in seq_along(dates19)) {
tweets19[[i]] <- searchTwitter('immigrant | immigration & -RT',
n=1000, lang='en',
since= dates19[i]) %>%
strip_retweets(strip_manual = TRUE, strip_mt = TRUE) %>%
twListToDF() %>%
tbl_df
}
# collapse tweets into a single data frame
tweets_joined19 <- bind_rows(tweets19) %>%
# remove duplicate tweets that were retrieved in multiple searches
unique()
str(tweets_joined19)
#20
# set the sequence of dates to search over
dates20 <- seq(as.Date("2016-05-16"), as.Date("2016-05-31"), by = "day") %>%
as.character()
# create a list to store the tweets
tweets20 <- vector("list", length(dates20))
# use a for loop to run the immigration search starting on each date
for(i in seq_along(dates20)) {
tweets20[[i]] <- searchTwitter('immigrant | immigration & -RT',
n=1000, lang='en',
since= dates20[i]) %>%
strip_retweets(strip_manual = TRUE, strip_mt = TRUE) %>%
twListToDF() %>%
tbl_df
}
# collapse tweets into a single data frame
tweets_joined20 <- bind_rows(tweets20) %>%
# remove duplicate tweets that were retrieved in multiple searches
unique()
str(tweets_joined20)
#21
# set the sequence of dates to search over
dates21 <- seq(as.Date("2016-06-01"), as.Date("2016-06-15"), by = "day") %>%
as.character()
# create a list to store the tweets
tweets21 <- vector("list", length(dates21))
# use a for loop to run the immigration search starting on each date
for(i in seq_along(dates21)) {
tweets21[[i]] <- searchTwitter('immigrant | immigration & -RT',
n=1000, lang='en',
since= dates21[i]) %>%
strip_retweets(strip_manual = TRUE, strip_mt = TRUE) %>%
twListToDF() %>%
tbl_df
}
# collapse tweets into a single data frame
tweets_joined21 <- bind_rows(tweets21) %>%
# remove duplicate tweets that were retrieved in multiple searches
unique()
str(tweets_joined21)
#22
# set the sequence of dates to search over
dates22 <- seq(as.Date("2016-06-16"), as.Date("2016-06-30"), by = "day") %>%
as.character()
# create a list to store the tweets
tweets22 <- vector("list", length(dates22))
# use a for loop to run the immigration search starting on each date
for(i in seq_along(dates22)) {
tweets22[[i]] <- searchTwitter('immigrant | immigration & -RT',
n=1000, lang='en',
since= dates22[i]) %>%
strip_retweets(strip_manual = TRUE, strip_mt = TRUE) %>%
twListToDF() %>%
tbl_df
}
# collapse tweets into a single data frame
tweets_joined22 <- bind_rows(tweets22) %>%
# remove duplicate tweets that were retrieved in multiple searches
unique()
str(tweets_joined22)
#23
# set the sequence of dates to search over
dates23 <- seq(as.Date("2016-07-01"), as.Date("2016-07-15"), by = "day") %>%
as.character()
# create a list to store the tweets
tweets23 <- vector("list", length(dates23))
# use a for loop to run the immigration search starting on each date
for(i in seq_along(dates23)) {
tweets23[[i]] <- searchTwitter('immigrant | immigration & -RT',
n=1000, lang='en',
since= dates23[i]) %>%
strip_retweets(strip_manual = TRUE, strip_mt = TRUE) %>%
twListToDF() %>%
tbl_df
}
# collapse tweets into a single data frame
tweets_joined23 <- bind_rows(tweets23) %>%
# remove duplicate tweets that were retrieved in multiple searches
unique()
str(tweets_joined23)
#24
# set the sequence of dates to search over
dates24 <- seq(as.Date("2016-07-16"), as.Date("2016-07-31"), by = "day") %>%
as.character()
# create a list to store the tweets
tweets24 <- vector("list", length(dates24))
# use a for loop to run the immigration search starting on each date
for(i in seq_along(dates24)) {
tweets24[[i]] <- searchTwitter('immigrant | immigration & -RT',
n=1000, lang='en',
since= dates24[i]) %>%
strip_retweets(strip_manual = TRUE, strip_mt = TRUE) %>%
twListToDF() %>%
tbl_df
}
# collapse tweets into a single data frame
tweets_joined24 <- bind_rows(tweets24) %>%
# remove duplicate tweets that were retrieved in multiple searches
unique()
str(tweets_joined24)
#25
# set the sequence of dates to search over
dates25 <- seq(as.Date("2016-08-01"), as.Date("2016-08-15"), by = "day") %>%
as.character()
# create a list to store the tweets
tweets25 <- vector("list", length(dates25))
# use a for loop to run the immigration search starting on each date
for(i in seq_along(dates25)) {
tweets25[[i]] <- searchTwitter('immigrant | immigration & -RT',
n=1000, lang='en',
since= dates25[i]) %>%
strip_retweets(strip_manual = TRUE, strip_mt = TRUE) %>%
twListToDF() %>%
tbl_df
}
# collapse tweets into a single data frame
tweets_joined25 <- bind_rows(tweets25) %>%
# remove duplicate tweets that were retrieved in multiple searches
unique()
str(tweets_joined25)
tweets_160416_to_160815 <- bind_rows(tweets18, tweets19, tweets20, tweets21, tweets22, tweets23, tweets24, tweets25)
write_csv(tweets_160416_to_160815, "tweets_160416_to_160815")
#26
# set the sequence of dates to search over
dates26 <- seq(as.Date("2016-08-15"), as.Date("2016-08-31"), by = "day") %>%
as.character()
# create a list to store the tweets
tweets26 <- vector("list", length(dates26))
# use a for loop to run the immigration search starting on each date
for(i in seq_along(dates26)) {
tweets26[[i]] <- searchTwitter('immigrant | immigration & -RT',
n=1000, lang='en',
since= dates26[i]) %>%
strip_retweets(strip_manual = TRUE, strip_mt = TRUE) %>%
twListToDF() %>%
tbl_df
}
# collapse tweets into a single data frame
tweets_joined26 <- bind_rows(tweets26) %>%
# remove duplicate tweets that were retrieved in multiple searches
unique()
str(tweets_joined26)
#27
# set the sequence of dates to search over
dates27 <- seq(as.Date("2016-09-01"), as.Date("2016-09-15"), by = "day") %>%
as.character()
# create a list to store the tweets
tweets27 <- vector("list", length(dates27))
# use a for loop to run the immigration search starting on each date
for(i in seq_along(dates27)) {
tweets27[[i]] <- searchTwitter('immigrant | immigration & -RT',
n=1000, lang='en',
since= dates27[i]) %>%
strip_retweets(strip_manual = TRUE, strip_mt = TRUE) %>%
twListToDF() %>%
tbl_df
}
# collapse tweets into a single data frame
tweets_joined27 <- bind_rows(tweets27) %>%
# remove duplicate tweets that were retrieved in multiple searches
unique()
str(tweets_joined27)
#28
# set the sequence of dates to search over
dates28 <- seq(as.Date("2016-09-16"), as.Date("2016-09-30"), by = "day") %>%
as.character()
# create a list to store the tweets
tweets28 <- vector("list", length(dates28))
# use a for loop to run the immigration search starting on each date
for(i in seq_along(dates28)) {
tweets28[[i]] <- searchTwitter('immigrant | immigration & -RT',
n=1000, lang='en',
since= dates28[i]) %>%
strip_retweets(strip_manual = TRUE, strip_mt = TRUE) %>%
twListToDF() %>%
tbl_df
}
# collapse tweets into a single data frame
tweets_joined28 <- bind_rows(tweets28) %>%
# remove duplicate tweets that were retrieved in multiple searches
unique()
str(tweets_joined28)
#29
# set the sequence of dates to search over
dates29 <- seq(as.Date("2016-10-01"), as.Date("2016-10-15"), by = "day") %>%
as.character()
# create a list to store the tweets
tweets29 <- vector("list", length(dates29))
# use a for loop to run the immigration search starting on each date
for(i in seq_along(dates29)) {
tweets29[[i]] <- searchTwitter('immigrant | immigration & -RT',
n=1000, lang='en',
since= dates29[i]) %>%
strip_retweets(strip_manual = TRUE, strip_mt = TRUE) %>%
twListToDF() %>%
tbl_df
}
# collapse tweets into a single data frame
tweets_joined29 <- bind_rows(tweets29) %>%
# remove duplicate tweets that were retrieved in multiple searches
unique()
str(tweets_joined29)
tweets_160816_to_161015 <- bind_rows(tweets26, tweets27, tweets28, tweets29)
write_csv(tweets_160816_to_161015, "tweets_160816_to_161015")
#30
# set the sequence of dates to search over
dates30 <- seq(as.Date("2016-10-16"), as.Date("2016-10-31"), by = "day") %>%
as.character()
# create a list to store the tweets
tweets30 <- vector("list", length(dates30))
# use a for loop to run the immigration search starting on each date
for(i in seq_along(dates30)) {
tweets30[[i]] <- searchTwitter('immigrant | immigration & -RT',
n=1000, lang='en',
since= dates30[i]) %>%
strip_retweets(strip_manual = TRUE, strip_mt = TRUE) %>%
twListToDF() %>%
tbl_df
}
# collapse tweets into a single data frame
tweets_joined30 <- bind_rows(tweets30) %>%
# remove duplicate tweets that were retrieved in multiple searches
unique()
str(tweets_joined30)
#31
# set the sequence of dates to search over
dates31 <- seq(as.Date("2016-11-01"), as.Date("2016-11-15"), by = "day") %>%
as.character()
# create a list to store the tweets
tweets31 <- vector("list", length(dates31))
# use a for loop to run the immigration search starting on each date
for(i in seq_along(dates31)) {
tweets31[[i]] <- searchTwitter('immigrant | immigration & -RT',
n=1000, lang='en',
since= dates31[i]) %>%
strip_retweets(strip_manual = TRUE, strip_mt = TRUE) %>%
twListToDF() %>%
tbl_df
}
# collapse tweets into a single data frame
tweets_joined31 <- bind_rows(tweets31) %>%
# remove duplicate tweets that were retrieved in multiple searches
unique()
str(tweets_joined31)
#32
# set the sequence of dates to search over
dates32 <- seq(as.Date("2016-11-16"), as.Date("2016-11-30"), by = "day") %>%
as.character()
# create a list to store the tweets
tweets32 <- vector("list", length(dates32))
# use a for loop to run the immigration search starting on each date
for(i in seq_along(dates32)) {
tweets32[[i]] <- searchTwitter('immigrant | immigration & -RT',
n=1000, lang='en',
since= dates32[i]) %>%
strip_retweets(strip_manual = TRUE, strip_mt = TRUE) %>%
twListToDF() %>%
tbl_df
}
# collapse tweets into a single data frame
tweets_joined32 <- bind_rows(tweets32) %>%
# remove duplicate tweets that were retrieved in multiple searches
unique()
str(tweets_joined32)
tweets_161016_to_161130 <- bind_rows(tweets30, tweets31, tweets32)
write_csv(tweets_161016_to_161130, "tweets_161016_to_161130.csv")
excel1 <- read_csv("tweets_til_151130.csv")
excel2 <- read_csv("tweets_151130_to_160415")
excel3 <- read_csv("tweets_160416_to_160815")
excel4 <- read_csv("tweets_160816_to_161015")
excel5 <- read_csv("tweets_161016_to_161130.csv")
allthetweets <- bind_rows(excel1,excel2,excel3,excel4,excel5)
write_csv(allthetweets, "allthetweets.csv")