tests/testthat/test_ranges.R

library(polmineR)
use(pkg = "RcppCWB", corpus = "REUTERS")
testthat::context("ranges")

test_that(
  "hits method",
  {
    rng_y <- ranges("REUTERS", query = "oil", progress = FALSE)
    expect_equal(nrow(rng_y@cpos), count("REUTERS", query = "oil")[["count"]])
    
    sc <- corpus("REUTERS") %>% subset(grep("saudi-arabia", places))
    expect_equal(nrow(ranges(sc, query = "oil")@cpos), count(sc, query = "oil")[["count"]])
    
    p <- partition("REUTERS", places = "saudi-arabia", regex = TRUE)
    y <- hits(p, query = "oil")
    expect_equal(nrow(ranges(p, query = "oil")@cpos), as.data.table(y)[["count"]])
    
    y <- hits("REUTERS", query = c(a = "oil", b = "barrel"))
    rng <- ranges("REUTERS", query = c(a = "oil", b = "barrel"))
    identical(as.data.table(y), as.data.table(rng))
    
    expect_error(ranges("REUTERS", query = c(a = "oil", "barrel")))
  }
)

Try the polmineR package in your browser

Any scripts or data that you put into this service are public.

polmineR documentation built on Nov. 2, 2023, 5:52 p.m.