tests/testthat/test-get-layer.R

# FeatureServer -----------------------------------------------------------

test_that("get_layer(): Must be `FeatureServer`, `MapServer` or `GroupLayer`", {
  skip_on_cran()
  # feature server
  server_url <- "https://services2.arcgis.com/j80Jz20at6Bi0thr/ArcGIS/rest/services/hexagons_state/FeatureServer"

  fsrv <- arc_open(server_url)

  expect_error(get_layer(server_url, 0))
})

test_that("get_layer(): Generic - name and id are mutually exclusive", {
  skip_on_cran()
  # feature server
  server_url <- "https://services2.arcgis.com/j80Jz20at6Bi0thr/ArcGIS/rest/services/hexagons_state/FeatureServer"

  fsrv <- arc_open(server_url)

  expect_error(get_layer(fsrv, 0, "break"))
})

test_that("get_layer(): `FeatureServer` by ID", {
  skip_on_cran()
  # feature server
  server_url <- "https://services2.arcgis.com/j80Jz20at6Bi0thr/ArcGIS/rest/services/hexagons_state/FeatureServer"

  fsrv <- arc_open(server_url)
  skip_on_cran()
  # feature server
  server_url <- "https://services2.arcgis.com/j80Jz20at6Bi0thr/ArcGIS/rest/services/hexagons_state/FeatureServer"

  fsrv <- arc_open(server_url)

  expect_snapshot(get_layer(fsrv, 0))
})

test_that("get_layer(): `FeatureServer` by name", {
  skip_on_cran()
  # feature server
  server_url <- "https://services2.arcgis.com/j80Jz20at6Bi0thr/ArcGIS/rest/services/hexagons_state/FeatureServer"

  fsrv <- arc_open(server_url)

  expect_snapshot(get_layer(fsrv, name = "states_hex"))
})


# MapServer ---------------------------------------------------------------

# map server
test_that("get_layer(): `MapServer` by ID", {
  skip_on_cran()
  map_url <- paste0(
    "https://services.arcgisonline.com/ArcGIS/rest/services/",
    "World_Imagery/MapServer"
  )

  msrv <- arc_open(map_url)

  expect_snapshot(get_layer(msrv, 3))
})

test_that("get_layer(): `MapServer` by name", {
  skip_on_cran()
  map_url <- paste0(
    "https://services.arcgisonline.com/ArcGIS/rest/services/",
    "World_Imagery/MapServer"
  )

  msrv <- arc_open(map_url)

  expect_snapshot(get_layer(msrv, name = "Citations"))
})


# GroupLayer --------------------------------------------------------------

test_that("get_layer(): `GroupLayer` by ID", {
  skip_on_cran()
  gurl <- "https://geodata.baltimorecity.gov/egis/rest/services/CitiMap/DOT_Layers/MapServer/0"
  glyr <- arc_open(gurl)

  expect_snapshot(get_layer(glyr, 2))
})

test_that("get_layer(): `GroupLayer` by name", {
  skip_on_cran()
  gurl <- "https://geodata.baltimorecity.gov/egis/rest/services/CitiMap/DOT_Layers/MapServer/0"
  glyr <- arc_open(gurl)

  expect_snapshot(get_layer(glyr, name = "Bus Stops"))
})

Try the arcgislayers package in your browser

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

arcgislayers documentation built on March 4, 2026, 9:06 a.m.