4

I'm trying to split a column into tokens using the tokenizers package but I keep receiving an error: could not find function "unnest_tokens". I am using R 3.5.3 and have installed and reinstalled dplyr, tidytext, tidyverse, tokenizers, tidyr, but still keep receiving the error.

I have also quit and restarted R and RStudio.

comments_tidy <- comments %>%
  unnest_tokens(word, txt) %>% #Break the comments into individual words
  filter(!word %in% undesirable_words) %>% #Remove undesirables
  anti_join(stop_words) #Data provided by the tidytext package

I receive the following:

Error in unnest_tokens(., word, txt) :
could not find function "unnest_tokens"

OTStats
  • 1,820
  • 1
  • 13
  • 22
GoodbyeJane
  • 63
  • 1
  • 5

3 Answers3

1

As mentioned in the comments, you may want to expand your code with library(x) statements. In addition, make sure that all the packages and their dependencies are installed. The following snippet would look up a given package (in this case dplyr) and install it if needed.

if ("dplyr" %in% installed.packages()[, "Package"]){ 
  cat("'dplyr' is installed.")
} else {
  install.packages("dplyr",dependencies=T)
}
library(dplyr)

The command installed.packages()[, "Package"])? gives you a list of all installed packages, that is a nice trick for debugging all kind of Function foo not found errors.

B--rian
  • 5,578
  • 10
  • 38
  • 89
0

Just be sure to run this first

install.packages("tidytext")
library(tidytext)

You only need to run the first line once - it will install the package.

You need to run the second line in each new R session, since that will load the package.

stevec
  • 41,291
  • 27
  • 223
  • 311
-2

Calling library (tidytext) and tidytext::unnest_tokens() solved the problem for me.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Seema
  • 7
  • 3