yes you are right. I ceated my first function "Get_tweets" here are my codes:
Get_tweets <- function(username){
tweets <- searchTwitter("realDonaldTrump", n=1000, lang = "en")
#converting tweets to data frame
tweets.df <- twListToDF(tweets)
#get text
tweets_text <- sapply(tweets, function(x) x$getText())
#cleaning text - remove people name, RT text, html links, punctuation, numbers
tweets_text1 <- gsub("(RT|via((?:\\b\\w*@\\w+)+))","",tweets_text)
tweets_text2 <- gsub("http[^[:blank:]]+", "",tweets_text1)
tweets_text3 <- gsub("@\\w+", "",tweets_text2)
tweets_text4 <- gsub("^[[:alnum:]]", "",tweets_text3)
tweets_text5 <- gsub("(RT|via((?:\\b\\w*@\\w+)+))","",tweets_text4)
#Creating corpus and cleaning tweets
tweets_text6 <- Corpus(VectorSource(tweets_text5))
tweets_text6 <- tm_map(tweets_text6, content_transformer(tolower))
tweets_text6 <- tm_map(tweets_text6, removeNumbers)
tweets_text6 <- tm_map(tweets_text6, removePunctuation)
tweets_text6 <- tm_map(tweets_text6, removeWords, stopwords("en"))
mystopwords <- c("amp", "like", "now", "can")
tweets_text6 <- tm_map(tweets_text6, stripWhitespace)
f <- content_transformer(function(x, pattern) gsub(pattern, "", x))
#remove non American standard code for information interchange(curly quotes and ellipsis)
#using function from package "text clean"
removenNonAscii<-function(x) textclean::replace_non_ascii(x)
tweets_text6 <- tm_map( tweets_text6, content_transformer(removenNonAscii))
toSpace<- content_transformer(function(x, pattren) { return (gsub(pattren, " ", x))})
tweets_text6 <- tm_map(tweets_text6, toSpace, "-")
tweets_text6 <- tm_map(tweets_text6, toSpace, ",")
tweets_text6 <- tm_map(tweets_text6, toSpace, "’")
tweets_text6 <- tm_map(tweets_text6, toSpace, " -")
tweets_text6 <- tm_map(tweets_text6, toSpace, "“")
tweets_text6 <- tm_map(tweets_text6, toSpace, "'")
tweets_text6 <- tm_map(tweets_text6, toSpace, "/")
final_text <- gsub("[[:punct:]]+", '', tweets_text6)
return(final_text)
}
Get_tweets(username)
I'm confused about input and output. argument.
what i wrote is right? my function always give me trump's tweets.