kbenoit / sophistication

R package associated with Benoit, Munger and Spirling (2017) paper(s)
42 stars 7 forks source link

Quanteda v2.0 and snippets_make() #18

Closed gmhurtado closed 3 years ago

gmhurtado commented 3 years ago

I believe I have found an issue regarding the snippets_make() function and later quanteda versions. With quanteda versions 2.0.0 and later installed, I get the following error when I call snippets_make():

> snippets_make(data_corpus_fifthgrade)
Error in select_docvars(attr(x, "docvars"), field, user = TRUE, system = FALSE,  : 
  field(s) docname not found

Here is the session info:

> sessionInfo()
R version 4.0.2 (2020-06-22)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Mojave 10.14.5

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] quanteda_2.1.1      sophistication_0.70

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.5          lattice_0.20-41     prettyunits_1.1.1  
 [4] ps_1.3.3            gtools_3.8.2        assertthat_0.2.1   
 [7] rprojroot_1.3-2     digest_0.6.25       R6_2.4.1           
[10] BradleyTerry2_1.1-2 plyr_1.8.6          backports_1.1.8    
[13] ggplot2_3.3.2       pillar_1.4.6        qvcalc_1.0.2       
[16] rlang_0.4.7         curl_4.3            rstudioapi_0.11    
[19] minqa_1.2.4         data.table_1.13.0   callr_3.4.3        
[22] nloptr_1.2.2.2      Matrix_1.2-18       reticulate_1.16    
[25] desc_1.2.0          devtools_2.3.1      splines_4.0.2      
[28] lme4_1.1-23         statmod_1.4.34      stringr_1.4.0      
[31] munsell_0.5.0       compiler_4.0.2      spacyr_1.2.1       
[34] pkgconfig_2.0.3     pkgbuild_1.1.0      tibble_3.0.3       
[37] brglm_0.6.2         fansi_0.4.1         crayon_1.3.4       
[40] withr_2.2.0         MASS_7.3-51.6       grid_4.0.2         
[43] nlme_3.1-148        jsonlite_1.7.0      xtable_1.8-4       
[46] gtable_0.3.0        lifecycle_0.2.0     magrittr_1.5       
[49] scales_1.1.1        RcppParallel_5.0.2  cli_2.0.2          
[52] stringi_1.4.6       reshape2_1.4.4      fs_1.5.0           
[55] remotes_2.2.0       testthat_2.3.2      ellipsis_0.3.1     
[58] stopwords_2.0       vctrs_0.3.2         boot_1.3-25        
[61] fastmatch_1.1-0     tools_4.0.2         glue_1.4.1         
[64] processx_3.4.3      profileModel_0.6.0  pkgload_1.1.0      
[67] yaml_2.2.1          colorspace_1.4-1    sessioninfo_1.1.1  
[70] memoise_1.1.0       usethis_1.6.1  

When I downloaded earlier quanteda versions (I tried with 1.0.0, 1.1.0, 1.4.0, 1.4.1), snippets_make() worked as expected.

Using quanteda version 1.5.0 also worked, but gave the following warning message:

Warning message:
'[[<-.corpus' is deprecated.
Use 'docvars' instead.
See help("Deprecated")

After looking through the changes associated with the release of quanteda v2.0, I believe the issue lies in the changes made to index operators for core objects, in particular the changes outlined here: https://github.com/quanteda/quanteda/wiki/indexing_core_objects. However, I am not entirely confident that this is the issue.

kbenoit commented 3 years ago

I think I just fixed it in https://github.com/kbenoit/sophistication/pull/19, can you take a look?

This is a good case in point for complete testing, since this function has neither a test nor an example - so we had no way to know if it was breaking before a user encountered the bug!