trinker / termco

Regular Expression Counts of Terms and Substrings
Other
25 stars 5 forks source link

tiered list without out 2nd tier causes termco error #61

Closed trinker closed 6 years ago

trinker commented 6 years ago
library(termco)

cat(
    "list(",
    "    list(",
    "        response_cries = c(\"\\boh\", \"\\bah\", \"\\baha\", \"\\bouch\", \"yuk\"),",
    "        back_channels = c(\"uh[- ]huh\", \"uhuh\", \"yeah\"),",
    "        summons = \"hey\",",
    "        justification = \"because\"",
    "    ),",
    "    list(),",
    "    list()",
    ")",

    file = file.path(tempdir(), 'cats.R'),
    sep = '\n'   
)

trpl_list <- read_term_list(file.path(tempdir(), 'cats.R'))

(x2 <- with(presidential_debates_2012, term_count(dialogue, TRUE, trpl_list)))

Results:

Error in `[.data.table`(data.table::setDT(DF), , `:=`(names(term.list),  : 
  LHS of := isn't column names ('character') or positions ('integer' or 'numeric')
trinker commented 6 years ago

This works:

(x2 <- with(presidential_debates_2012, term_count(dialogue, TRUE, trpl_list[[1]])))

So detect emty tiers if only one unlist one level in both term_count and read_term_list families of functions and warn

trinker commented 6 years ago

This would catch it:

trpl_list <- read_term_list(file.path(tempdir(), 'cats.R'))

trpl_list2 <- list(
    list(
        response_cries = c("\\boh", "\\bah", "\\baha", "\\bouch", "yuk"),
        back_channels = c("uh[- ]huh", "uhuh", "yeah"),
        summons = "hey",
        justification = "because"
    ),
    list(summons ='the'),
    list(summons = 'it', justification = 'ed\\s')
)

trpl_list3 <- trpl_list[[1]]

is.list(trpl_list[[1]]) & length(trpl_list) == 1
is.list(trpl_list2[[1]]) & length(trpl_list2) == 1
is.list(trpl_list3[[1]]) & length(trpl_list3) == 1