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

Feature: Add a robust argument to hereR::isoline. #118

Closed
nbanion opened this issue Feb 26, 2021 · 3 comments
Closed

Feature: Add a robust argument to hereR::isoline. #118

nbanion opened this issue Feb 26, 2021 · 3 comments
Assignees
Labels
feature New feature or enhancement

Comments

@nbanion
Copy link

nbanion commented Feb 26, 2021

Sometimes hereR::isoline fails for specific cases in poi, causing an error. Consider adding a robust argument that allows the function to return values for the successful isolines and NAs for the unsuccessful ones. This argument would take a logical and default to FALSE.

I often find myself using this pattern:

library(dplyr)
library(hereR)
library(purrr)
library(tidyr)

# Failproof version of isoline (returns just the geometry for use in mutate).
safely_isoline <- function(...) {
  fxn <- safely(isoline)
  value <- fxn(...)
  if (is.null(value$error)) value$result$geometry else NA
}

# A sf object with points.
my_sf <- ... 

# Example usage: Replace some point geometries with isoline geometries.
my_sf %>%
  group_by(id) %>%           # Some unique identifier.
  nest(data = geometry) %>%  # A sfc with point geometries.
  mutate(geometry = map(data, safely_isoline)) %>%
  select(-data) %>% unnest(geometry) %>%
  ungroup()

The failing cases may deserve a bug report of their own. I haven't figured out the cause; all I know is that it seems to happen for specific cases when combined with specific function arguments. This issue is only concerned with moving past these failures.

@nbanion nbanion added the feature New feature or enhancement label Feb 26, 2021
@munterfi
Copy link
Owner

Hi, thanks for reporting.

Unfortunately I don't quite understand the requested feature, and therefore try to narrow it down to two cases:

  • If a request fails on the API side (response status is not 200), then the response is completely ignored (NULL) by hereR::isoline. So for this request, the rows with this id will be missing in the return value.

  • Or is it an error that occurs within the function hereR::isoline? That means the request to the HERE API was successful, but something in the processing of the response from the API into an sf object fails.

In the first case the option with a boolean robust argument seems to be a reasonable option, which would replace the missing rows (NULL) with a row where every value is NA, except from the request id. In the second case we should rather try to fix the error in the function. If it is the second case, do you have a reproducible example? In your example code POIs are missing, which trigger this error.

@munterfi munterfi self-assigned this Feb 28, 2021
@nbanion
Copy link
Author

nbanion commented Feb 28, 2021

Let me put together a reproducible example before you invest more effort.

@munterfi
Copy link
Owner

Closing in favor of #132.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants