0

tidytext 新手并遇到错误。

当我尝试将“单词”以外的任何内容传递给 unnest_tokens 函数的令牌参数时,我得到:

eval 中的错误(替代(expr)、envir、enclos):找不到对象“txt”

甚至无法运行文档示例...

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

当我在自己的代码(不是示例)上运行它时,我得到:

eval 中的错误(substitute(expr)、envir、enclos):无效的参数类型

我希望这是一个'facepalm'类型的错误:)。奇怪的是我什至无法运行帮助示例......

谢谢!

4

1 回答 1

0

我无法使用所有这些软件包的当前 CRAN 版本重现这些错误。

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

reprex 包(v0.2.0) 于 2018 年 5 月 8 日创建。

也许您应该尝试从 CRAN 重新安装这些软件包?

于 2018-05-09T00:05:46.570 回答