Running ‘coco.R’
  Running ‘surface.R’
  Running ‘surface_coco.R’
Running the tests in ‘tests/coco.R’ failed.
Complete output:
  > library(CorporaCoCo)
  > library(data.table)
  > library(unittest, quietly=TRUE)
  > 
  > test_for_error <- function(code, expected_regexp = '.+') {
  +     tryCatch({
  +             code
  +             return("No error returned")
  +         }, error = function(e) {
  +             if(grepl(expected_regexp, e$message)) return(TRUE)
  +             return(c(e$message, "Expected error did not match - ", expected_regexp))
  +         }
  +     )
  + }
  > 
  > 
  > # -----
  > # tests
  > # -----
  > 
  > ok_group("main", {
  +     A <- surface(
  +         x = c(
  +             rep(c("a", "man", NA), 100),
  +             rep(c("a", "plan", NA), 100),
  +             rep(c("a", "cat", NA), 100),
  +             rep(c("a", "badger", NA), 50),
  +             rep(c("a", "snake", NA), 100),
  +             rep(c("the", "man", NA), 100),
  +             rep(c("the", "plan", NA), 100),
  +             rep(c("another", "man", NA), 100),
  +             rep(c("another", "plan", NA), 100)
  +         ),
  +         span = '1R'
  +     )
  +     B <- surface(
  +         x = c(
  +             rep(c("a", "man", NA), 60),
  +             rep(c("a", "plan", NA), 100),
  +             rep(c("a", "cat", NA), 50),
  +             rep(c("a", "badger", NA), 100),
  +             rep(c("a", "mushroom", NA), 100),
  +             rep(c("a", "canal", NA), 40),
  +             rep(c("the", "man", NA), 60),
  +             rep(c("the", "plan", NA), 100),
  +             rep(c("the", "canal", NA), 40),
  +             rep(c("another", "man", NA), 60),
  +             rep(c("another", "plan", NA), 100),
  +             rep(c("another", "canal", NA), 40)
  +         ),
  +         span = '1R'
  +     )
  +     nodes <- c("a", "the")
  + 
  +     rv <- coco(A, B, nodes = nodes, fdr = 1.0)
  + 
  +     ok( is(rv, 'coco'), "is class 'coco'")
  +     ok( is(rv, 'data.table'), "is class 'data.table'")
  +     ok( is(rv, 'data.frame'), "is class 'data.frame'")
  + 
  +     ok( all.equal(sort(nodes), sort(unique(rv$x))), "expected nodes in results")
  +     ok( all(rv$y %in% c('man', 'plan', 'canal', 'cat', 'badger', 'mushroom', 'snake')), "all collocates of nodes from both corpora in results")
  + 
  +     ok( all.equal(rv[x=='a' & y=='cat', effect_size], -rv[x=='a' & y=='badger', effect_size]), "effect_size is symetric") 
  +     ok( rv[x=='a' & y=='cat', effect_size] < 0 &&
  +         rv[x=='a' & y=='cat', CI_upper] < 0
  +     , "effect_size, CI_upper when co-occurrence ratio is greater in corpus A") 
  +     ok( rv[x=='a' & y=='badger', effect_size] > 0 &&
  +         rv[x=='a' & y=='badger', CI_lower] > 0
  +     , "effect_size, CI_lower when co-occurrence ratio is greater in corpus B") 
  +     ok(
  +         rv[x=='a' & y=='snake', effect_size] < 0 && is.infinite(rv[x=='a' & y=='snake', effect_size]) &&
  +         rv[x=='a' & y=='snake', CI_lower] < 0 && is.infinite(rv[x=='a' & y=='snake', CI_lower]) &&
  +         rv[x=='a' & y=='snake', CI_upper] < 0 && is.finite(rv[x=='a' & y=='snake', CI_upper])
  +     , "effect_size, CI_upper, CI_lower if collocate is only in corpus A")
  +     ok(
  +         rv[x=='a' & y=='canal', effect_size] > 0 && is.infinite(rv[x=='a' & y=='canal', effect_size]) &&
  +         rv[x=='a' & y=='canal', CI_lower] > 0 && is.finite(rv[x=='a' & y=='canal', CI_lower]) &&
  +         rv[x=='a' & y=='canal', CI_upper] > 0 && is.infinite(rv[x=='a' & y=='canal', CI_upper])
  +     , "effect_size, CI_upper, CI_lower if collocate is only in corpus B")
  + 
  +     rv_2 <- rv[x == "a"]
  +     rv_3 <- coco(A, B, nodes = "a", fdr = 1.0)
  +     attr(rv_2, 'coco_metadata') <- NULL
  +     attr(rv_3, 'coco_metadata') <- NULL
  +     ok(identical(rv_2, rv_3), "single node (as a string)")
  + 
  +     rv <- coco(A, B, nodes = nodes)
  +     ok( all(identical(c("a", "a", "a", "a", "a", "a", "the", "the"), sort(rv$x)), identical(c("badger", "canal", "canal", "cat", "man", "man", "mushroom", "snake"), sort(rv$y))), "correct set of significant results")
  + 
  +     ok( identical(attr(rv, 'coco_metadata')$nodes, nodes), "object metadata nodes look good")
  + 
  +     # collocates filter
  +     rv_f <- coco(A, B, nodes = nodes, collocates = c("badger", "man"))
  +     ok( identical(rv_f[, -"p_adjusted"], rv[y %in% c("badger", "man"), -"p_adjusted"]), "collocates filter - vector - rows")
  +     ok( ! isTRUE(all.equal(rv_f$p_adjusted, rv[y %in% c("badger", "man")]$p_adjusted)), "collocates filter - vector - p_adjusted values")
  + 
  +     rv_f <- coco(A, B, nodes = nodes, collocates = "cat")
  +     ok( identical(rv_f[, -"p_adjusted"], rv[y == "cat", -"p_adjusted"]), "collocates filter - string - rows")
  +     ok( isTRUE(all.equal(rv_f$p_value, rv_f$p_adjusted)), "collocates filter - string - p_adjusted values")
  + })
  # main
  Error in `[.data.table`(DT, !is.na(x) & !is.na(y), `:=`(M, sum(H) - H),  : 
    SETLENGTH() cannot be applied to an ALTVEC object.
  Calls: ok_group -> surface -> [ -> [.data.table
  Execution halted
Running the tests in ‘tests/surface.R’ failed.
Complete output:
  > library(CorporaCoCo)
  > library(data.table)
  > library(unittest, quietly=TRUE)
  > 
  > test_for_error <- function(code, expected_regexp = '.+') {
  +     tryCatch({
  +             code
  +             return("No error returned")
  +         }, error = function(e) {
  +             if(grepl(expected_regexp, e$message)) return(TRUE)
  +             return(c(e$message, "Expected error did not match - ", expected_regexp))
  +         }
  +     )
  + }
  > 
  > 
  > # -----
  > # tests
  > # -----
  > 
  > ok_group("parse_span", {
  +     expected <- list(left = 5, right = 0)
  +     got <- local({parse_span('5L')}, asNamespace('CorporaCoCo'))
  +     ok( identical(got, expected), "5L")
  +     expected <- list(left = 0, right = 5)
  +     got <- local({parse_span('5R')}, asNamespace('CorporaCoCo'))
  +     ok( identical(got, expected), "5R")
  +     expected <- list(left = 5, right = 5)
  +     got <- local({parse_span('5LR')}, asNamespace('CorporaCoCo'))
  +     ok( identical(got, expected), "5LR")
  +     expected <- list(left = 5, right = 5)
  +     got <- local({parse_span('5RL')}, asNamespace('CorporaCoCo'))
  +     ok( identical(got, expected), "5RL")
  +     expected <- list(left = 5, right = 5)
  +     got <- local({parse_span('5R5L')}, asNamespace('CorporaCoCo'))
  +     ok( identical(got, expected), "5R5L")
  +     expected <- list(left = 1, right = 5)
  +     got <- local({parse_span('1L5R')}, asNamespace('CorporaCoCo'))
  +     ok( identical(got, expected), "1L5R")
  +     expected <- list(left = 2, right = 3)
  +     got <- local({parse_span('3R2L')}, asNamespace('CorporaCoCo'))
  +     ok( identical(got, expected), "3R2L")
  +     expected <- list(left = 2, right = 0)
  +     got <- local({parse_span('2L0R')}, asNamespace('CorporaCoCo'))
  +     ok( identical(got, expected), "2L0R")
  +     expected <- list(left = 0, right = 2)
  +     got <- local({parse_span('0L2R')}, asNamespace('CorporaCoCo'))
  +     ok( identical(got, expected), "0L2R")
  + 
  +     # errors
  +     ok(test_for_error(local({parse_span('cat')}, asNamespace('CorporaCoCo')), "span"),  "cat  (error)")
  +     ok(test_for_error(local({parse_span('5B')}, asNamespace('CorporaCoCo')), "span"),   "5B   (error)")
  +     ok(test_for_error(local({parse_span('5RR')}, asNamespace('CorporaCoCo')), "span"),  "5RR  (error)")
  +     ok(test_for_error(local({parse_span('5LL')}, asNamespace('CorporaCoCo')), "span"),  "5LL  (error)")
  +     ok(test_for_error(local({parse_span('5L2L')}, asNamespace('CorporaCoCo')), "span"), "5L2L (error)")
  +     ok(test_for_error(local({parse_span('LR')}, asNamespace('CorporaCoCo')), "span"),   "LR   (error)")
  +     ok(test_for_error(local({parse_span('0LR')}, asNamespace('CorporaCoCo')), "span"),  "0LR  (error)")
  +     ok(test_for_error(local({parse_span('0L0R')}, asNamespace('CorporaCoCo')), "span"), "0L0R (error)")
  + })
  # parse_span
  ok - 5L
  ok - 5R
  ok - 5LR
  ok - 5RL
  ok - 5R5L
  ok - 1L5R
  ok - 3R2L
  ok - 2L0R
  ok - 0L2R
  ok - cat  (error)
  ok - 5B   (error)
  ok - 5RR  (error)
  ok - 5LL  (error)
  ok - 5L2L (error)
  ok - LR   (error)
  ok - 0LR  (error)
  ok - 0L0R (error)
  > 
  > 
  > ok_group("main", {
  + 
  +     x <- c("a", "man", "a", "plan", "a", "canal", "panama")
  +     expected <- data.table(
  +         x =            c("a", "a",     "a",   "a",      "a",    "canal",  "man", "man",  "plan", "plan"),
  +         y =            c("a", "canal", "man", "panama", "plan", "panama", "a",   "plan", "a",    "canal"),
  +         H = as.integer(c( 2,   1,       1,     1,        1,      1,        1,     1,      1,      1)),
  +         M = as.integer(c( 4,   5,       5,     5,        5,      0,        1,     1,      1,      1))
  +     )
  +     setkey(expected, x, y)
  +     rv <- surface(x, span = '2R')
  +     ok( identical(rv, expected), "defaults")
  + 
  +     # include NA
  +     new_rows <- data.table(
  +         x =            c("canal", "panama"),
  +         y =            c( NA,      NA),
  +         H = as.integer(c( 1,       2)),
  +         M = as.integer(c( NA,      NA))
  +     )
  +     expected <- rbindlist(list(expected, new_rows), use.names = TRUE)
  +     setkey(expected, x, y)
  +     assign('unittest_surface_include_na', TRUE, pos = CorporaCoCo:::pkg_vars)
  +     rv <- surface(x, span = '2R')
  +     ok( identical(rv, expected), "include NA")
  +     ok( sum(rv$H) == 2 * length(x), "include NA - sum of counts is span times length(x)")
  +     assign('unittest_surface_include_na', FALSE, pos = CorporaCoCo:::pkg_vars)
  + 
  +     # some NAs in x
  +     x <- c("a", "man", "a", "plan", NA, NA, "a", "canal", "panama")
  +     expected <- data.table(
  +         x =            c("a", "a",     "a",   "a",      "a",    "canal",  "man", "man"),
  +         y =            c("a", "canal", "man", "panama", "plan", "panama", "a",   "plan"),
  +         H = as.integer(c( 1,   1,       1,     1,        1,      1,        1,     1)),
  +         M = as.integer(c( 4,   4,       4,     4,        4,      0,        1,     1))
  +     )
  +     setkey(expected, x, y)
  +     rv <- surface(x, span = '2R')
  +     ok( identical(rv, expected), "NAs in x")
  + 
  +     # some NAs in x and include NA
  +     new_rows <- data.table(
  +         x =            c("a", "plan", "canal", "panama", NA,  NA,  NA),
  +         y =            c( NA,  NA,     NA,      NA,      NA, "a", "canal"),
  +         H = as.integer(c( 1,   2,      1,       2,       1,   2,   1)),
  +         M = as.integer(c( NA,  NA,     NA,      NA,      NA,  NA,  NA))
  +     )
  +     expected <- rbindlist(list(expected, new_rows), use.names = TRUE)
  +     setkey(expected, x, y)
  +     assign('unittest_surface_include_na', TRUE, pos = CorporaCoCo:::pkg_vars)
  +     rv <- surface(x, span = '2R')
  +     ok( identical(rv, expected), "NAs in x and include NA")
  +     ok( sum(rv$H) == 2 * length(x), "NAs in x and include NA - sum of counts is span times length(x)")
  +     assign('unittest_surface_include_na', FALSE, pos = CorporaCoCo:::pkg_vars)
  + 
  +     # span left
  +     x <- c("a", "man", "a", "plan", "a", "canal", "panama")
  +     expected <- data.table(
  +         x =            c("a", "canal", "man", "panama", "plan", "panama", "a",   "plan", "a",    "canal"),
  +         y =            c("a", "a",     "a",   "a",      "a",    "canal",  "man", "man",  "plan", "plan"),
  +         H = as.integer(c( 2,   1,       1,     1,        1,      1,        1,     1,      1,      1)),
  +         M = as.integer(c( 2,   1,       0,     1,        1,      1,        3,     1,      3,      1))
  +     )
  +     setkey(expected, x, y)
  +     rv <- surface(x, span = '2L')
  +     ok( identical(rv, expected), "span left")
  + 
  +     # span left, include NA
  +     new_rows <- data.table(
  +         x =            c("a", "man"),
  +         y =            c( NA, NA),
  +         H = as.integer(c( 2,  1)),
  +         M = as.integer(c( NA, NA))
  +     )
  +     expected <- rbindlist(list(expected, new_rows), use.names = TRUE)
  +     setkey(expected, x, y)
  +     assign('unittest_surface_include_na', TRUE, pos = CorporaCoCo:::pkg_vars)
  +     rv <- surface(x, span = '2L')
  +     ok( identical(rv, expected), "span left, include NA")
  +     ok( sum(rv$H) == 2 * length(x), "span left, include NA - sum of counts is span times length(x)")
  +     assign('unittest_surface_include_na', FALSE, pos = CorporaCoCo:::pkg_vars)
  + 
  +     # span both
  +     x <- c("a", "man", "a", "plan", "a", "canal", "panama")
  +     expected <- data.table(
  +         x =            c("a", "a",     "a",   "a",      "a",    "canal",  "man", "man",  "plan", "plan",  "canal", "panama", "panama", "plan", "canal"),
  +         y =            c("a", "canal", "man", "panama", "plan", "panama", "a",   "plan", "a",    "canal", "a",     "a",      "canal",  "man",  "plan"),
  +         H = as.integer(c( 4,   1,       2,     1,        2,      1,        2,     1,      2,      1,       1,       1,        1,        1,      1)),
  +         M = as.integer(c( 6,   9,       8,     9,        8,      2,        1,     2,      2,      3,       2,       1,        1,        3,      2))
  +     )
  +     setkey(expected, x, y)
  +     rv <- surface(x, span = '2LR')
  +     ok( identical(rv, expected), "span both")
  + 
  +     # span both, some NAs, include NA
  +     x <- c("a", "man", NA, NA, "a", "plan", NA, NA, "a", "canal", "panama")
  +     expected <- data.table(
  +         x =            c("a",  "a", "a",    "a",     "a",      "man",  "man",  NA,    NA, NA,  NA,     NA,     "plan", "plan", "canal", "canal",  "canal", "panama", "panama", "panama"),
  +         y =            c("man", NA, "plan", "canal", "panama", "a",     NA,   "man", "a", NA, "plan", "canal", "a",     NA,    "a",     "panama",  NA,     "a",      "canal",   NA),
  +         H = as.integer(c( 1,    8,   1,      1,       1,        1,      3,     2,     6,  4,   3,      1,       1,      3,      1,       1,        2,       1,        1,        2)),
  +         M = as.integer(c( 3,    NA,  3,      3,       3,        0,      NA,    NA,    NA, NA,  NA,     NA,      0,      NA,     1,       1,        NA,      1,        1,        NA))
  +     )
  +     setkey(expected, x, y)
  +     assign('unittest_surface_include_na', TRUE, pos = CorporaCoCo:::pkg_vars)
  +     rv <- surface(x, span = '2LR')
  +     ok( identical(rv, expected), "span both, NAs in x and include NA" )
  +     ok( sum(rv$H) == 2 * 2 * length(x), "span both, include NA - sum of counts is 2 * span times length(x)")
  +     assign('unittest_surface_include_na', FALSE, pos = CorporaCoCo:::pkg_vars)
  + })
  # main
  Error in `[.data.table`(DT, !is.na(x) & !is.na(y), `:=`(M, sum(H) - H),  : 
    SETLENGTH() cannot be applied to an ALTVEC object.
  Calls: ok_group -> surface -> [ -> [.data.table
  Execution halted
  # Looks like you passed all 17 tests.
Running the tests in ‘tests/surface_coco.R’ failed.
Complete output:
  > library(CorporaCoCo)
  > library(data.table)
  > library(unittest, quietly=TRUE)
  > 
  > ok_group("main", {
  +     a = c(
  +         rep(c("a", "man", NA), 100),
  +         rep(c("a", "plan", NA), 100),
  +         rep(c("the", "man", NA), 100),
  +         rep(c("the", "plan", NA), 100),
  +         rep(c("another", "man", NA), 100),
  +         rep(c("another", "plan", NA), 100)
  +     )
  +     b = c(
  +         rep(c("a", "man", NA), 60),
  +         rep(c("a", "plan", NA), 100),
  +         rep(c("a", "canal", NA), 40),
  +         rep(c("the", "man", NA), 60),
  +         rep(c("the", "plan", NA), 100),
  +         rep(c("the", "canal", NA), 40),
  +         rep(c("another", "man", NA), 60),
  +         rep(c("another", "plan", NA), 100),
  +         rep(c("another", "canal", NA), 40)
  +     )
  +     nodes <- c("a", "the")
  + 
  +     rv_1 <- coco(
  +         surface(a, span = '1R'),
  +         surface(b, span = '1R'),
  +         nodes = nodes, fdr = 0.01
  +     )
  +     rv_2 <- surface_coco(a, b, span = '1R', nodes = nodes, fdr = 0.01)
  +     ok( identical(rv_1, rv_2), "surface_coco")
  + 
  +     rv_3 <- coco(
  +         surface(a, span = '1R', collocates = "man"),
  +         surface(b, span = '1R', collocates = "man"),
  +         nodes = nodes, fdr = 0.01, collocates = "man"
  +     )
  +     rv_4 <- surface_coco(a, b, span = '1R', nodes = nodes, fdr = 0.01, collocates = "man")
  +     ok( identical(rv_3, rv_4), "surface_coco with collocates filter")
  + })
  # main
  Error in `[.data.table`(DT, !is.na(x) & !is.na(y), `:=`(M, sum(H) - H),  : 
    SETLENGTH() cannot be applied to an ALTVEC object.
  Calls: ok_group -> coco -> %in% -> surface -> [ -> [.data.table
  Execution halted