cbail / textnets

R package to perform automated text analysis using network techniques
MIT License
210 stars 62 forks source link

VisTextNet() won't run when node_type = "words" #16

Closed kelseygonzalez closed 3 years ago

kelseygonzalez commented 4 years ago

Running

library(textnets)
data(sotu)
sotu_first_speeches <- sotu %>% 
  group_by(president) %>% 
  slice(1L)
prepped_sotu <- PrepText(sotu_first_speeches, 
                         groupvar = "president", 
                         textvar = "sotu_text", 
                         node_type = "groups", 
                         tokenizer = "words", 
                         pos = "nouns", 
                         remove_stop_words = TRUE,
                         compound_nouns = TRUE)
sotu_text_network <- CreateTextnet(prepped_sotu)
VisTextNet(sotu_text_network, alpha=.1, label_degree_cut = 3)

works fine.

However, when I try and run the word-to-word network, I get an error.

library(textnets)
data(sotu)
sotu_first_speeches <- sotu %>% 
  group_by(president) %>% 
  slice(1L)
prepped_sotu <- PrepText(sotu_first_speeches, 
                         groupvar = "president", 
                         textvar = "sotu_text", 
                         node_type = "words", 
                         tokenizer = "words", 
                         pos = "nouns", 
                         remove_stop_words = TRUE,
                         compound_nouns = TRUE)
sotu_text_network <- CreateTextnet(prepped_sotu)
VisTextNet(sotu_text_network)

I get the error

Using 'sparse_stress' with 250 pivots as default layout
Error in if (!is.na(weights)) { : argument is of length zero
cbail commented 4 years ago

Thanks @kelseygonzalez it looks like the issue is that this code creates such a large network that it makes ggraph crash (I'm able to run the code above taking just the first 1,000 lines of either dataset, for example). I'm not sure how to handle this- I could put more warnings in the vignette, or create a warning message that says "try plotting fewer nodes" (best would be to actually handle the problem in with/ggraph, I guess, but that's a much taller order ;(