Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gracefully handle NA values #118

Open
JosiahParry opened this issue May 21, 2024 · 1 comment
Open

Gracefully handle NA values #118

JosiahParry opened this issue May 21, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@JosiahParry
Copy link

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

@anthonynorth anthonynorth added the bug Something isn't working label May 27, 2024
@anthonynorth
Copy link
Member

This looks overly strict. NaN, NA, Inf should all render as 0 elevation.

As a temporary workaround, use get_elevation = scale_identity(frequency), or remove the validation rule entirely (hack!) validate_get_elevation.Layer <- function(...) NULL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants