JohnCoene / graphTweets

📣 Visualise networks of Twitter interactions
http://graphtweets.john-coene.com/
Other
46 stars 5 forks source link

gt_co_edges #9

Open NataliaUmansky opened 4 years ago

NataliaUmansky commented 4 years ago

Thank you for developing this great tool! When I try to create a hashtag co-occurance network with the gt_co_edges function, I get the following error:

Error in as.character(x) : cannot coerce type 'closure' to vector of type 'character'

How could I fix it?

JohnCoene commented 4 years ago

Hi Natalia,

Could you please try with the Github version?

remotes::install_github("JohnCoene/graphTweets")

Let me know if it still does not work afterwards.

NataliaUmansky commented 4 years ago

Hi John,

Thank you for your quick response! I managed to fix the error with strsplit(tweets$hashtags, " ")

Thanks again!

JohnCoene commented 4 years ago

Ah OK I see, thank you!

Could you please tell how you had those tweets saved so I can reproduce this on my end and improve the package so it checks for such things.

NataliaUmansky commented 4 years ago

The tweets were in a data frame produced by rtweet. However, if I replicate your example and run a new query, the hashtag variable is saved as a list of vectors, while in my dataset the hashtag variable was of type character (i.e. hashtags were considered one string, even though they had a space between them).

strsplit(tweets$hashtags, " ") splits the string and creates a vector of strings, and the hashtag variable becomes a list of vectors.

JohnCoene commented 4 years ago

Ok I see.

library(purrr)

tweets <- rtweet::search_tweets("rstats")

# flatten list of tweets in character string separated by space
tweets$hashtags <- map(tweets$hashtags, function(x){paste0(x, collapse = " ")}) %>% unlist()

# reproduce list
tweets$hashtags <- strsplit(tweets$hashtags, " ") 

I'll add checks for this in the package. Thanks again Natalia.