I'm trying to reduce my copy-paste by using a function (see below). However, I struggle with understanding "how" to properly implement functions in this context. In this example, my for loop only returns the last term of interest. My final goal is to create a single data table (tibble) with all the data included.
What am I doing wrong in my implementation of the for loop in order to run the search_tweet function for each of my terms of interest?
library(here)
#> here() starts at C:/Users/renedherrera/AppData/Local/Temp/RtmpWMhoFi/reprex32007f8a5dd7
library(tidyverse)
library(rtweet) # search twitter data for hashtags of interest
#>
#> Attaching package: 'rtweet'
#> The following object is masked from 'package:purrr':
#>
#> flatten
# hashtags of interest
hashtags <- c("#adcsm", # adrenal cancer
"#amsm", #advanced metastatic cancer
"#ancsm", #anal cancer
"#ayacsm", #adolescent and young adult cancer
"#bcsm" #breast cancer
) #this continues on for several more hashtags
# functions to return twitter status data
adcsm <- search_tweets("#adcsm", include_rts = FALSE, n = 5)
amsm <- search_tweets("#amsm", include_rts = FALSE, n = 5)
ancsm <- search_tweets("#ancsm", include_rts = FALSE, n = 5)
ayacsm <- search_tweets("#ayacsm", include_rts = FALSE, n = 5)
bcsm <- search_tweets("#bcsm", include_rts = FALSE, n = 5) # and so on
# but it is repetitive and I think some function is better
# i tried a for loop but it's not quite right
for(i in hashtags) {
i <- search_tweets(i, include_rts = FALSE, n = 5)
}
Created on 2020-11-13 by the reprex package (v0.3.0)