Question

So i am having troubles in saving my tweets , when i collected them and applied sapply on them they appear in this form

 some_txt = sapply(tweets, function(x) x$getText())


[1] "RT @JanoImLukesSlut: #HarryHas17MillionFollowParty\n♔ RT\n♔Follow me\n♔Ask4follow back\n♔Follow ALL who RTs\n♔Gain\n♔Drink pepsi feel sexyyy\n#Sto…"               
 [2] "RT @abria_valerie: Pepsi is like crack to me. I gotta have it."                                                                                                                  
 [3] "@JLinn6 having to stop for dr. Pepper bc someone doesn't like Pepsi. #picky #spoiledbrat #watchoutonlylikesdr.'s"                                                                
 [4] "RT @cyberscott1975: The coca cola truck can bugger off! I want a Pepsi Max Xmas Truck!í ½íºš"                                                                                    
 [5] "í ½í²•í ½í²•í ½í²•Mmm That Spicy Chicken Sandwich And Fries And Pepsi From Wendy's Was A1í ½í²¦"                                                                                 
 [6] "@JatnnaP05 @Alexandergr_ @IannErnesto @WilberJE ENTRA dale a GALERIA luego vota por : attabeira https://t.co/hh0Q5tkHzx  #HelpMe"                                                
 [7] "RT @supersunnytime: wallowing in a sea of pop punk and self-hatred"                                                                                                              
 [8] "These bitches love soda Pepsi and Cola"                                                                                                                                          
 [9] "RT @Lmao: waiter: \"what drink would you like\" \nme: \"тнє вℓσσ∂ σƒ му єηємιєѕ\" \nwaiter: \nme: \nwaiter: \nme: \nwaiter: \nme: \nwaiter: \"is pepsi o…"

               .......................

However when i apply a write csv to it . and then read it back out it does not come back the same format

   write.csv(some_txt, file = file.choose(), row.names = TRUE, sep = ',', col.names = TRUE)
   some_txt = read.csv(file.choose(), row.names = 1, sep = ',')

it instead comes back as

x
1            RT @JanoImLukesSlut: #HarryHas17MillionFollowParty\n♔ RT\n♔Follow me\n♔Ask4follow back\n♔Follow ALL who RTs\n♔Gain\n♔Drink pepsi feel sexyyy\n#Sto…
2                                                                                                               RT @abria_valerie: Pepsi is like crack to me. I gotta have it.
3                                                             @JLinn6 having to stop for dr. Pepper bc someone doesn't like Pepsi. #picky #spoiledbrat #watchoutonlylikesdr.'s
4                                                                                 RT @cyberscott1975: The coca cola truck can bugger off! I want a Pepsi Max Xmas Truck!í ½íºš
5                                                                              í ½í²•í ½í²•í ½í²•Mmm That Spicy Chicken Sandwich And Fries And Pepsi From Wendy's Was A1í ½í²¦
6                                             @JatnnaP05 @Alexandergr_ @IannErnesto @WilberJE ENTRA dale a GALERIA luego vota por : attabeira https://t.co/hh0Q5tkHzx  #HelpMe
7                                                                                                           RT @supersunnytime: wallowing in a sea of pop punk and self-hatred
8                                                                                                                                       These bitches love soda Pepsi and Cola
9  RT @Lmao: waiter: "what drink would you like" \nme: "тнє вℓσσ∂ σƒ му єηємιєѕ" \nwaiter: \nme: \nwaiter: \nme: \nwaiter: \nme: \nwaiter: "is pepsi o…

                                      ......

Any idea on how to give it back the same value ? Im using csv because i want to collect these tweets manually .

this is the str() example of the some_txt (it's 50 tweets thats why its 1:50 )

  chr [1:50] "@psychicpebble AMEN THANK YOU FOR NOT TALKING ABOUT THAT PEPSI SHIT." ...

Edit:

this is the str() example of the output after reading(example)

     'data.frame':  50 obs. of  1 variable:
     $ x: Factor w/ 43 levels "$39 = Jack'n'Coke, Vodka & Pepsi, and a 24 oz.      Miller Lite. Fml.",..: 10 24 33 9 13 39 9 21 6 31 ...

New Update: I tried your method thomas, it's not exactly what i wanted , cause in my original some_txt i could do this

  > some_txt[2]
   [1] "RT @Nada_7Q: #تابعني_اتابعك\n@toomy48\n@m_alzuhair\n@alzheri33    \n@hallm77\n@tooomy48\n@RT_FAEF\n@Nada_7Q★☆★☆\n@abosaef11\n@adoan3\n@Msolfje\n@Khalid_06…"
  > some_txt[1]
  [1] "RT @CodeClue: 50 CL Pepsi is unnecessary tbh."
  > some_txt[3]
  [1] "I just ate all my Dad's very expensive cheese and it's supposed to be eaten slowly with a nice glass of red not a Pepsi Max"

After applying the stringAsFactor to the read.csv , it still prints out the same thing, however the str() type has changed slightly. But i would want the entire list to be chr[1:50] ,not just a single one . Also it only has a single list element in it not like my original some_txt above. I really hope someone can help me >.< this has been giving me a headache

Was it helpful?

Solution

This is what i did to put it back into a list of its original form.

 for(i in 1:length(some_txt[,1])){
  some_txt1 = c(some_txt1,some_txt[,1][i])
 }

I just basically create a for loop and just loop them back into a list.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top