Skip to content

Gracefully handle NA values  #118

Description

@JosiahParry

Repro:

Using a column with NA values the error message is provided:

Error in `add_polygon_layer()`:
! Failed to create layer
Caused by error in `validate_get_elevation.default()`:
! Assertion failed: is.numeric(accessor_data) && all_finite(accessor_data)
✖ Column `frequency` is invalid for accessor `get_elevation`; it must be a <numeric> vector

The main part of the error message says "it must be a vector". I only just now noticed it said "all_finite(accessor_data)". The error message should indicate the true cause of the error. In this case the presence of NA values.

I've attached a shapefile you can use to repro the issue.

library(sf)
library(rdeck)
deck_df <- read_sf("~/downloads/deck-df.shp")

rdeck(
  initial_view_state = view_state(
    center = {
      sf::st_bbox(deck_df) |>
        sf::st_as_sfc() |>
        sf::st_centroid()
    }[[1]],
    zoom = 10,
    bearing = 45,
    pitch = 40.5
  )
) |> 
  add_polygon_layer(
    data = deck_df,
    id = "1234",
    coverage = 1,
    auto_highlight = TRUE,
    extruded = TRUE,
    get_polygon = geometry,
    get_elevation = n
  )


rdeck(
  initial_view_state = view_state(
    center = {
      sf::st_bbox(deck_df) |>
        sf::st_as_sfc() |>
        sf::st_centroid()
    }[[1]],
    zoom = 10,
    bearing = 45,
    pitch = 40.5
  )
) |> 
  add_polygon_layer(
    data = deck_df,
    id = "1234",
    coverage = 1,
    auto_highlight = TRUE,
    extruded = TRUE,
    get_polygon = geometry,
    get_elevation = frequency
  )

deck-df.zip

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions