0

I am currently trying to get a wordcloud in R with a script that worked when I first used it. I am now rechecking my markdown document and got the following issue.

I am working with rtweet to create a wordcloud for the amount of tweets on a special topic.

tokenized_tweets <- tidy_tweets %>% select(status_id, text) %>% unnest_tokens(word, text)

custom_stopwords <- tibble(lexicon = "custom", word = c("t.co", "https"))

tokenized_tweets %>%
  anti_join(stop_words) %>%
  anti_join(custom_stopwords) %>%
  count(word) %>%
  with(wordcloud(word, n, max.words = 25))

However when I use this script (which worked for me), I get the following output:

Joining, by = "word"Joining, by = "word"Error in UseMethod("as.quoted") : no applicable method for 'as.quoted' applied to an object of class "function"

Thank you for your help!

NelsonGon
  • 13,015
  • 7
  • 27
  • 57
  • Hi questionmaster, to make the question more reproducible, please edit as shown in [this post](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). In general, if you cannot copy and paste your code and have it run without any issues in a fresh R session, chances are no one can. – NelsonGon Jan 12 '20 at 13:29

1 Answers1

0

For easier reference, find below a reproducible example created with reprex. Everything works just fine, and it should work for you in a clean R session (restart R, delete all objects, and re-run your code).

Looking at your error message, it seems that you have a custom_stopwords function in your workspace... consider giving any other name to the data frame you call custom_stopwords.

library("rtweet")
library("tidytext")
library("tibble")
library("dplyr")
library("wordcloud")

tidy_tweets <- rtweet::search_tweets(q = "punk") 

tokenized_tweets <- tidy_tweets %>% select(status_id, text) %>%
  unnest_tokens(word, text)

custom_stopwords <- tibble(lexicon = "custom", word = c("t.co", "https"))

tokenized_tweets %>%
  anti_join(tidytext::stop_words) %>%
  anti_join(custom_stopwords) %>%
  count(word) %>%
  with(wordcloud(word, n, max.words = 25))
#> Joining, by = "word"
#> Joining, by = "word"

Created on 2020-01-12 by the reprex package (v0.3.0)

giocomai
  • 3,043
  • 21
  • 24
  • 1
    It's hard to know what's going on in the original code, since the OP didn't include data. Without being able to recreate anything, I wouldn't tell them to delete something in their environment – camille Jan 12 '20 at 18:25
  • fair point, I edited it out of this tentative answer. it wouldn't make any difference honestly since they created an object with the same name, so it was just a way to point at where the issue may be, but as you suggested, better not to suggest to delete anything – giocomai Jan 12 '20 at 18:32