-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsearch.R
38 lines (30 loc) · 1.13 KB
/
search.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
## search terms
nicar18conf <- c("NICAR18", "NICAR2018", "IRE_NICAR")
## use since_id from previous search (if exists)
if (file.exists(file.path("data", "search.rds"))) {
since_id <- readRDS(file.path("data", "search.rds"))
since_id <- since_id$status_id[1]
} else {
since_id <- NULL
}
## search for up to 100,000 tweets mentioning nicar18
rt <- search_tweets(
paste(nicar18conf, collapse = " OR "),
n = 1e5, verbose = FALSE,
since_id = since_id,
retryonratelimit = TRUE
)
## if there's already a search data file saved, then read it in,
## drop the duplicates, and then update the `rt` data object
if (file.exists(file.path("data", "search.rds"))) {
## bind rows (for tweets AND users data)
rt <- do.call("rbind", list(rt, readRDS(file.path("data", "search.rds"))))
## determine whether each observation has a unique status ID
kp <- !duplicated(rt$status_id) & !is.na(rt$status_id)
## the rows of users should correspond with the tweets
rt <- rt[kp, ]
}
## save the data
saveRDS(rt, file.path("data", "search.rds"))
## save shareable data (only status_ids)
saveRDS(rt[, "status_id"], file.path("data", "search-ids.rds"))