Skip to content
This repository has been archived by the owner on Sep 9, 2022. It is now read-only.

Commit

Permalink
fix ecoregion internals, was erroring on subsetting the input data.frame
Browse files Browse the repository at this point in the history
  • Loading branch information
sckott committed Apr 7, 2020
1 parent d082477 commit 6c6e134
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions R/ecoregion.R
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,19 @@ eco_region <- function(x, dataset = "meow", region,

x <- do_coords(x, lat, lon)
z <- sf::st_as_sf(x, coords = c("longitude", "latitude"))
z <- sf::st_set_crs(z, 4326)
z <- sf::st_set_crs(z, "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs")

ref_sf <- switch(dataset, meow = regions_meow(), fao = regions_fao())
er_split <- strsplit(region, ":")[[1]]
ref_target <- ref_sf[ref_sf[[ er_split[1] ]] %in% er_split[2], ]

bb <- sf::st_join(z, ref_target, join = sf::st_within)
wth <- tibble::as_tibble(x[is.na(bb$FID), ])
bb_is_na <- bb[is.na(bb$FID), ]
wth <- tibble::as_tibble(x[x$key %in% bb_is_na$key, ])

if (drop) {
x <- tibble::as_tibble(x[!is.na(bb$FID), ])
bb_not_na <- bb[!is.na(bb$FID), ]
x <- tibble::as_tibble(x[x$key %in% bb_not_na$key, ])
}
if (NROW(wth) == 0) wth <- NA
row.names(wth) <- NULL
Expand Down
2 changes: 1 addition & 1 deletion R/taxonomy-funs.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#' out bade data points as an attribute you can access. Default: `TRUE`
#' @return Returns a data.frame, with attributes
#' @examples
#' if (requireNamespace("rgbif", quietly = TRUE)) {
#' if (requireNamespace("rgbif", quietly = TRUE) && interactive()) {
#' library("rgbif")
#' res <- rgbif::occ_data(limit = 200)$data
#' } else {
Expand Down
2 changes: 1 addition & 1 deletion man/taxonomy.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6c6e134

Please sign in to comment.