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

df passed to "get_elev_point" does not pass loc_check #94

Open
dibamus opened this issue Nov 14, 2023 · 0 comments
Open

df passed to "get_elev_point" does not pass loc_check #94

dibamus opened this issue Nov 14, 2023 · 0 comments

Comments

@dibamus
Copy link

dibamus commented Nov 14, 2023

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

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

No branches or pull requests

1 participant