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

occfilt_geo() only works with "x" and "y" columns #343

Closed
wevertonbio opened this issue Jul 28, 2023 · 1 comment
Closed

occfilt_geo() only works with "x" and "y" columns #343

wevertonbio opened this issue Jul 28, 2023 · 1 comment

Comments

@wevertonbio
Copy link

Hi Santiago,

I found an error in the occfilt_geo() function. The function only works when the coordinate columns are named "x" and "y". If we run the function example, it works perfectly:

# Environmental variables
somevar <- system.file("external/somevar.tif", package = "flexsdm")
somevar <- terra::rast(somevar)

plot(somevar)

# Species occurrences
data("spp")
spp
spp1 <- spp %>% dplyr::filter(species == "sp1", pr_ab == 1)

somevar[[1]] %>% plot()
points(spp1 %>% select(x, y))

#Change column names
spp2 <- spp1 %>% dplyr::rename(longitude = x, latitude = y)

# Using Moran method
filtered_1 <- occfilt_geo(
  data = spp,
  x = "x",
  y = "y",
  env_layer = somevar,
  method = c("moran"),
  prj = crs(somevar)
)

However, when I rename the columns with the coordinates to "longitude" and "latitude," I get the following error:

#Change column names
spp2 <- spp1 %>% dplyr::rename(longitude = x, latitude = y)

# Using Moran method
filtered_1 <- occfilt_geo(
  data = spp2,
  x = "longitude",
  y = "latitude",
  env_layer = somevar,
  method = c("moran"),
  prj = crs(somevar)
)
Error in `[.data.frame`(da, c(x, y)) : colunas indefinidas selecionadas
@sjevelazco
Copy link
Owner

Hi @wevertonbio
Thank you so much for reporting this error. It was fixed. Please reinstall the package.
Best

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

2 participants