USEPA/elevatr

df passed to "get_elev_point" does not pass loc_check

Opened this issue · 0 comments

Thanks for your work on this package, it's very useful for my work on reptile and amphibian biodiversity on Sulawesi.

as of 0.99 when I pass a df to "get_elev_point," with columns not explicitly labelled "x" and "y," I get the following error:
Error in[.data.frame(x, coords) : undefined columns selected

reprex with the traceback


df<- data.frame(longitude=121.2647, latitude = -1.113770)
get_elev_point(df, prj = "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs", 
       src = "aws", z = 14)

Error in `[.data.frame`(x, coords) : undefined columns selected
> traceback()
9: stop("undefined columns selected")
8: `[.data.frame`(x, coords)
7: x[coords]
6: lapply(x[coords], as.numeric)
5: as.data.frame(lapply(x[coords], as.numeric))
4: st_as_sf.data.frame(x = locations, coords = c("x", "y"), crs = prj)
3: sf::st_as_sf(x = locations, coords = c("x", "y"), crs = prj)
2: loc_check(locations, prj)
1: get_elev_point(df, prj = "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs", 
       src = "aws", z = 14)

This issue appears to be with line 55 in the internal function loc_check:
locations <- sf::st_as_sf(x = locations, coords = c("x", "y"), crs = prj)
if you pass a df to this and the first two columns are not explicitly "x" and "y," it fails.
This is easy enough for me to get around, but this used to work fine so some of my published code relied on passing a df with "longitude" and "latitude" columns, and I would think the package overall would benefit from being robust to this. If there's a reason this can't be made robust, I'd suggest emphasizing in the get_elev_point documentation that the columns must be explicitly named "x" and "y."

Thanks for your work on this package!

Isaac