Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

r issue, not sure what I'm doing wrong

  • 03-05-2017 08:10PM
    #1
    Registered Users, Registered Users 2 Posts: 756 ✭✭✭


    Bear with me with this one.

    I am using r to extract tweets using the twitter api and that works fine. I am saving my results to .csv using the write.csv2 funtion which is also fine.

    When i open the csv file, in some cases the tweet is spread over multiple rows. This is down to character returns (\n) being in the tweet text.

    I have tried using a str_replace_all but it doesn't achieve the desired results when saved to csv.

    here is a snippet of my code;
    tweets_listDB <- searchTwitter(searchString, n=750, lang = "en", resultType = 'recent')
    str_replace_all(tweets_listDB.text, "[\n]", " ")
    
    # each tweets_list element contains several attributes such as:
    tweets.df <- twListToDF(tweets_listDB)
    
    The error i am getting is 
    Error in stri_replace_all_regex(string, pattern, fix_replacement(replacement),  : 
      object 'tweets_listDB.text' not found
    

    I'm pretty new to r, and i'm sure this was working for me last night, any idea what i am doing wrong?

    By way of example, i would like to remove the '\n' from the following tweet
    ethicalpaul: Come on, @CitiBikeNYC, PLEASE get the Port Authority area figured out!!\n\nI want to #bikeNYC !! (And I'm paying to d&#226;&#8364;&#166; https://t.co/4jSbbrcRoq"
    

    my list can have multiple items, i want to remove any '\n' from all tweets in my list.


Advertisement