building R package

I got bit confused since creating my own r package. It's the first time I'm creating it so I don't know if it's a stupid question but i still ask.. I got Donald Trump tweets through API, I cleaned the text and analyze the sentiment of tweets through nrc lexicon and plot it.
My question is my package will work only for trump tweets or for any kind of tweets to analyse sentiment?
Please help me!

This sounds like a report not a package, a package would contain functions that perform these things based on input arguments, so the answer to your question would be: It depends on how you have programed your functions.

If you need more specific help, please provide a proper REPRoducible EXample (reprex) illustrating your issue.

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.

It's all you search for in the function.
Swap it for a parameter, add a 2nd parameter to your function. Call it with the value of the Twitter handle

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.