graphTweets icon indicating copy to clipboard operation
graphTweets copied to clipboard

gt_co_edges

Open NataliaUmansky opened this issue 5 years ago • 5 comments

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?

NataliaUmansky avatar Apr 21 '20 16:04 NataliaUmansky

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.

JohnCoene avatar Apr 21 '20 19:04 JohnCoene

Hi John,

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

Thanks again!

NataliaUmansky avatar Apr 22 '20 07:04 NataliaUmansky

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.

JohnCoene avatar Apr 22 '20 08:04 JohnCoene

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.

NataliaUmansky avatar Apr 22 '20 08:04 NataliaUmansky

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.

JohnCoene avatar Apr 22 '20 08:04 JohnCoene