benmarwick / wordcountaddin

Word counts and readability statistics in R markdown documents
Other
337 stars 33 forks source link

Word count fails because koRpus lang package koRpus.lang.en is not installed/loaded #13

Closed naupaka closed 5 years ago

naupaka commented 5 years ago

As of the last few days (weeks?), word count fails on the template Rmd file in RStudio with the following error:

> wordcountaddin::text_stats(filename = "~/Desktop/test.Rmd")
Error in (function (classes, fdef, mtable)  : 
  unable to find an inherited method for function ‘describe’ for signature ‘"NULL"’

It fails both with a filename specified, as well as with interactive use (e.g. cursor in Rmd file, select from addin menu).

Debugging led me to the problem, which is in the non-exported prep_text_korpus() function. This fails because by default (?) the command

devtools::install_github("benmarwick/wordcountaddin", type = "source", dependencies = TRUE)

doesn't install the necessary korPus language packages, as described here:

?available.koRpus.lang

When in debugging mode, this is the error:

Browse[5]> koRpus:::tokenize(text, lang = "en", format = "obj")
    Error: Unknown tag definition requested: en
    See ?available.koRpus.lang() for a list of supported languages.

I was able to resolve this issue with koRpus::install.koRpus.lang("en") and then load the package (library(koRpus.lang.en)) before running the wordcountaddin::test_stats() function.

> library(koRpus.lang.en)
Loading required package: koRpus
Loading required package: sylly
For information on available language packages for 'koRpus', run

  available.koRpus.lang()

and see ?install.koRpus.lang()
> wordcountaddin::text_stats(filename = "~/Desktop/test.Rmd")

|Method          |koRpus      |stringi       |
|:---------------|:-----------|:-------------|
|Word count      |101         |100           |
|Character count |564         |563           |
|Sentence count  |7           |Not available |
|Reading time    |0.5 minutes |0.5 minutes   |

Perhaps the solution is to add koRpus.lang.en to the list of imports?

or at least issue a warning that the language package needs to be installed?

Here's the spot where that is called in the wordcountaddin code:

https://github.com/benmarwick/wordcountaddin/blob/cbe935973723220d7545f0c3b3f6be6d8d234146/R/hello.R#L212

My session_info:

> devtools::session_info()
─ Session info ──────────────────────────────────────────────────────────────────────────────────────────
 setting  value                       
 version  R version 3.5.1 (2018-07-02)
 os       macOS  10.14.1              
 system   x86_64, darwin15.6.0        
 ui       RStudio                     
 language (EN)                        
 collate  en_US.UTF-8                 
 ctype    en_US.UTF-8                 
 tz       America/Los_Angeles         
 date     2018-11-03                  

─ Packages ──────────────────────────────────────────────────────────────────────────────────────────────
 package        * version date       lib source                                    
 assertthat       0.2.0   2017-04-11 [1] CRAN (R 3.5.0)                            
 backports        1.1.2   2017-12-13 [1] CRAN (R 3.5.0)                            
 base64enc        0.1-3   2015-07-28 [1] CRAN (R 3.5.0)                            
 callr            3.0.0   2018-08-24 [1] CRAN (R 3.5.0)                            
 cli              1.0.1   2018-09-25 [1] CRAN (R 3.5.0)                            
 crayon           1.3.4   2017-09-16 [1] CRAN (R 3.5.0)                            
 curl             3.2     2018-03-28 [1] CRAN (R 3.5.0)                            
 data.table       1.11.8  2018-09-30 [1] CRAN (R 3.5.0)                            
 desc             1.2.0   2018-05-01 [1] CRAN (R 3.5.0)                            
 devtools         2.0.1   2018-10-26 [1] CRAN (R 3.5.1)                            
 digest           0.6.18  2018-10-10 [1] CRAN (R 3.5.0)                            
 fs               1.2.6   2018-08-23 [1] CRAN (R 3.5.0)                            
 glue             1.3.0   2018-07-17 [1] CRAN (R 3.5.0)                            
 highr            0.7     2018-06-09 [1] CRAN (R 3.5.0)                            
 knitr            1.20    2018-02-20 [1] CRAN (R 3.5.0)                            
 koRpus         * 0.11-5  2018-10-28 [1] CRAN (R 3.5.0)                            
 koRpus.lang.en * 0.1-2   2018-03-21 [1] CRAN (R 3.5.0)                            
 magrittr         1.5     2014-11-22 [1] CRAN (R 3.5.0)                            
 memoise          1.1.0   2017-04-21 [1] CRAN (R 3.5.0)                            
 pkgbuild         1.0.2   2018-10-16 [1] CRAN (R 3.5.0)                            
 pkgload          1.0.2   2018-10-29 [1] CRAN (R 3.5.0)                            
 prettyunits      1.0.2   2015-07-13 [1] CRAN (R 3.5.0)                            
 processx         3.2.0   2018-08-16 [1] CRAN (R 3.5.0)                            
 ps               1.2.0   2018-10-16 [1] CRAN (R 3.5.0)                            
 purrr            0.2.5   2018-05-29 [1] CRAN (R 3.5.0)                            
 R6               2.3.0   2018-10-04 [1] CRAN (R 3.5.0)                            
 Rcpp             0.12.19 2018-10-01 [1] CRAN (R 3.5.0)                            
 remotes          2.0.2   2018-10-30 [1] CRAN (R 3.5.0)                            
 rlang            0.3.0.1 2018-10-25 [1] CRAN (R 3.5.1)                            
 rprojroot        1.3-2   2018-01-03 [1] CRAN (R 3.5.0)                            
 rstudioapi       0.8     2018-10-02 [1] CRAN (R 3.5.0)                            
 sessioninfo      1.1.0   2018-09-25 [1] CRAN (R 3.5.0)                            
 stringi          1.2.4   2018-07-20 [1] CRAN (R 3.5.0)                            
 sylly          * 0.1-5   2018-07-29 [1] CRAN (R 3.5.0)                            
 sylly.en         0.1-3   2018-03-19 [1] CRAN (R 3.5.0)                            
 testthat         2.0.1   2018-10-13 [1] CRAN (R 3.5.0)                            
 usethis          1.4.0   2018-08-14 [1] CRAN (R 3.5.0)                            
 withr            2.1.2   2018-03-15 [1] CRAN (R 3.5.0)                            
 wordcountaddin   0.2.0   2018-11-03 [1] Github (benmarwick/wordcountaddin@cbe9359)
 yaml             2.2.0   2018-07-25 [1] CRAN (R 3.5.0)                            

[1] /Library/Frameworks/R.framework/Versions/3.5/Resources/library
benmarwick commented 5 years ago

Thanks for your thorough and detailed issue! Seems like there have been some changes to the koRpus pkg that I need to catch up with. I have encountered a slightly different issue to you in running the tests locally and on travis, so it seems like there are few things that need attention!

I've added the koRpus.lang.en requirement in there now, but that doesn't solve my test failure, so I'll keep looking.

unable to find an inherited method for function 'describe' for signature '"NULL"'
1: wordcountaddin:::text_stats_fn_(eleven_words) at testthat/test_wordcountaddin.R:7
2: sylly::describe(k1) at G:/My Documents/My Various Things/wordcountaddin/R/hello.R:239
3: (function (classes, fdef, mtable) 
   {
       methods <- .findInheritedMethods(classes, 
           fdef, mtable)
       if (length(methods) == 1L) 
           return(methods[[1L]])
       else if (length(methods) == 
           0L) {
           cnames <- paste0("\"", 
               vapply(classes, as.character, 
                   ""), "\"", collapse = ", ")
           stop(gettextf("unable to find an inherited method for function %s for signature %s", 
               sQuote(fdef@generic), 
               sQuote(cnames)), domain = NA)
       }
       else stop("Internal error in finding inherited methods; didn't return a unique method", 
           domain = NA)
   })(list("NULL"), new("standardGeneric", 
       .Data = function (obj) 
       standardGeneric("describe"), 
       generic = structure("describe", package = "sylly"), 
       package = "sylly", group = list(), 
       valueClass = character(0), 
       signature = "obj", default = NULL, 
       skeleton = (function (obj) 
       stop("invalid call in method dispatch to 'describe' (no default method)", 
           domain = NA))(obj)), <environment>)
4: stop(gettextf("unable to find an inherited method for function %s for signature %s", 
       sQuote(fdef@generic), sQuote(cnames)), 
       domain = NA)

== testthat results  =========
OK: 0 SKIPPED: 0 FAILED: 1
1. Error: (unknown) (@test_wordcountaddin.R#7) 
benmarwick commented 5 years ago

Green light on travis with https://github.com/benmarwick/wordcountaddin/commit/ad4e077dbd7b3fb5c45c654f225feb85a90dc602, so I think we might have got on top of this one. Would you mind to try and let me know what you see?

naupaka commented 5 years ago

Works great in a fresh rocker/rstudio docker container, so I think it should be good to go! Thanks for the quick fix -- I'm using this add-in in my bioinformatics class this semester.