tests/testthat/test_lookup_coords.R

context("lookup_coords")

test_that("lookup_coords returns coords data", {
  skip_on_cran()
  
  kcmo <- lookup_coords("kansas city, mo")
  expect_gt(cor(kcmo$point, c(39.0997, 94.5786)), 0.9)
  tor <- lookup_coords("toronto canada")
  expect_gt(cor(tor$point, c(43.6532, 79.3832)), 0.9)
  
  x <- lookup_coords("usa")
  expect_equal(is.list(x), TRUE)
  expect_named(x)
  expect_true("box" %in% names(x))

  x <- lookup_coords("world")
  expect_equal(is.list(x), TRUE)
  expect_named(x)
  expect_true("box" %in% names(x))

  gmk <- Sys.getenv("GOOGLE_MAPS_KEY")
  if (!is.null(gmk) && !identical(gmk, "")) {
    x <- lookup_coords("New York, NY")
    expect_equal(is.list(x), TRUE)
    expect_named(x)
    expect_true("box" %in% names(x))
  }
  rtweet:::set_renv(GOOGLE_KEY = gmk)
  rtweet:::set_renv(GOOGLE_MAPS_KEY = "")
  if (!is.null(gmk) && !identical(gmk, "")) {
    x <- lookup_coords("New York, NY")
    expect_equal(is.list(x), TRUE)
    expect_named(x)
    expect_true("box" %in% names(x))
  }
  e <- names(Sys.getenv())
  g <- grep("google|gmap", e, ignore.case = TRUE, value = TRUE)
  if (length(g) > 0) {
    ng <- as.list(rep("", length(g)))
    names(ng) <- g
    do.call(Sys.setenv, ng)
  }
  expect_error(lookup_coords("London, UK"))
})

Try the rtweet package in your browser

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

rtweet documentation built on Jan. 11, 2020, 9:11 a.m.