bnosac / pattern.nlp

R package to perform sentiment analysis and Parts of Speech tagging for Dutch/French/English/German/Spanish/Italian
Other
67 stars 17 forks source link

Error when the input string does not contain any token #3

Closed lepennec closed 5 years ago

lepennec commented 7 years ago

As explained in the title,

pattern_pos(" ", "english") Error in [<-.data.table(x, j = name, value = value) : Cannot use := to add columns to a null data.table (no columns), currently. You can use := to add (empty) columns to a 0-row data.table (1 or more empty columns), though. In addition: Warning message: In is.na(tags$word) : is.na() applied to non-(list or vector) of type 'NULL'

This is due to the fact that there is no token in the string and this corner case is not handled by the wrapper.

Yours,

Erwan

jwijffels commented 7 years ago

thanks for the report. will be looking in to it but you can also easily fetch this in your script as in

x <- "   "
if(nchar(gsub("[[:space:]]", "", x) == 0)){
  stop("no tokens in x") 
}else{
  pattern_pos(x, "english")
}
jwijffels commented 5 years ago

Closing as it's up to the user to handle such cases without tokens.