0

New to tidytext and running into an error.

When I try to pass anything other than "words" into the token argument for the unnest_tokens function I get:

Error in eval(substitute(expr), envir, enclos) : object 'txt' not found

Cant even run the documentation examples...

library(dplyr)
library(janeaustenr)
library(tidytext)

d <- data_frame(txt = prideprejudice)

d %>% unnest_tokens(word, txt, token = "words") #Works
d %>% unnest_tokens(sentence, txt, token = "sentences") #doesnt work
d %>% unnest_tokens(ngram, txt, token = "ngrams", n = 2) #doesnt work

When I run it on my own code (not the example), i get:

Error in eval(substitute(expr), envir, enclos) : invalid argument type

Im hoping this is a 'facepalm' type of mistake :). Strange that I cant even run the help example though...

Thanks!

Thomas
  • 1

1 Answers1

0

I am not able to reproduce these errors, with the current CRAN versions of all of these packages.

library(dplyr)
library(janeaustenr)
library(tidytext)

d <- data_frame(txt = prideprejudice)

d %>% unnest_tokens(word, txt, token = "words") 
#> # A tibble: 122,204 x 1
#>    word     
#>    <chr>    
#>  1 pride    
#>  2 and      
#>  3 prejudice
#>  4 by       
#>  5 jane     
#>  6 austen   
#>  7 chapter  
#>  8 1        
#>  9 it       
#> 10 is       
#> # ... with 122,194 more rows

d %>% unnest_tokens(sentence, txt, token = "sentences") 
#> # A tibble: 7,066 x 1
#>    sentence                                                               
#>    <chr>                                                                  
#>  1 pride and prejudice  by jane austen    chapter 1   it is a truth unive…
#>  2 however little known the feelings or views of such a man may be on his…
#>  3 "\"my dear mr."                                                        
#>  4 "bennet,\" said his lady to him one day, \"have you heard that netherf…
#>  5 mr.                                                                    
#>  6 bennet replied that he had not.                                        
#>  7 "\"but it is,\" returned she; \"for mrs."                              
#>  8 "long has just been here, and she told me all about it.\""             
#>  9 mr.                                                                    
#> 10 bennet made no answer.                                                 
#> # ... with 7,056 more rows

d %>% unnest_tokens(ngram, txt, token = "ngrams", n = 2)
#> # A tibble: 122,203 x 1
#>    ngram         
#>    <chr>         
#>  1 pride and     
#>  2 and prejudice 
#>  3 prejudice by  
#>  4 by jane       
#>  5 jane austen   
#>  6 austen chapter
#>  7 chapter 1     
#>  8 1 it          
#>  9 it is         
#> 10 is a          
#> # ... with 122,193 more rows

Created on 2018-05-08 by the reprex package (v0.2.0).

Perhaps you should try re-installing these packages from CRAN?

Julia Silge
  • 10,848
  • 2
  • 40
  • 48