Skip to content

Add warning/error if at least one column name is missing #1388

Description

@stefan-mueller

Describe the bug

If a column name of a data.frame is missing, constructing a corpus() still works. Yet, summary(), for example, results in an error due to undefined docvars. I was wondering whether we might add a test to the corpus construction stage to check that column names are not NA?

Reproducible code

library(quanteda)

df <- data.frame(text = letters, docvar1 = paste(letters, letters), num = 1:26, 
  stringsAsFactors = F)

colnames(df) <- c("text", "docvar1")

corp <- corpus(df)

corp
#> Corpus consisting of 26 documents and 1 docvar.

summary(corp)
#> Warning in nsentence.character(object, ...): nsentence() does not correctly
#> count sentences in all lower-cased text
#> Error in `[.data.frame`(x, !is_system & !is_text): undefined columns selected

Expected behavior

Already return an error (or at least a warning) when a corpus is constructed from an object with missing column names.

R version 3.5.0 (2018-04-23)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Sierra 10.12.6

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

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

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

other attached packages:
[1] reprex_0.1.2   quanteda_1.3.0

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.17       compiler_3.5.0     pillar_1.2.1       formatR_1.5       
 [5] plyr_1.8.4         tools_3.5.0        stopwords_0.9.0    digest_0.6.15     
 [9] debugme_1.1.0      lubridate_1.7.4    evaluate_0.10.1    memoise_1.1.0     
[13] tibble_1.4.2       gtable_0.2.0       lattice_0.20-35    rlang_0.2.1       
[17] Matrix_1.2-14      fastmatch_1.1-0    rstudioapi_0.7     yaml_2.1.19       
[21] blogdown_0.6       xfun_0.1           withr_2.1.2        stringr_1.3.1     
[25] knitr_1.20         devtools_1.13.5    rprojroot_1.3-2    grid_3.5.0        
[29] data.table_1.11.2  R6_2.2.2           rmarkdown_1.9      bookdown_0.7      
[33] callr_2.0.3        whisker_0.3-2      ggplot2_2.2.1      spacyr_0.9.9      
[37] magrittr_1.5       backports_1.1.2    scales_0.5.0       htmltools_0.3.6   
[41] assertthat_0.2.0   colorspace_1.3-2   stringi_1.2.2      lazyeval_0.2.1    
[45] RcppParallel_4.4.0 munsell_0.4.3      crayon_1.3.4  

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions