Skip to content

Commit

Permalink
refactor: rename list.ok to allow_list
Browse files Browse the repository at this point in the history
- refactor: rename list.ok to allow_list
- refactor: update staticimports
- refactor: add input check to st_bbox_ext
- refactor: stop importing map, map_lgl, and discard from purrr
- feat: drop write_exif + start exporting write_exif_from separately
- refactor: improve checking of logical inputs for is_sf and related functions
  • Loading branch information
elipousson committed Mar 26, 2023
1 parent 73ac3bf commit 411357a
Show file tree
Hide file tree
Showing 28 changed files with 412 additions and 458 deletions.
4 changes: 0 additions & 4 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ export(st_trim)
export(st_union_by)
export(st_union_ext)
export(transform_sf)
export(write_exif)
export(write_exif_from)
export(write_sf_cache)
export(write_sf_ext)
Expand All @@ -168,7 +167,6 @@ importFrom(cli,cli_warn)
importFrom(cli,pluralize)
importFrom(cliExtras,cli_abort_ifnot)
importFrom(cliExtras,cli_ask)
importFrom(cliExtras,cli_paths)
importFrom(cliExtras,cli_warn_ifnot)
importFrom(cliExtras,cli_yesno)
importFrom(cliExtras,cls_vec)
Expand Down Expand Up @@ -208,10 +206,8 @@ importFrom(janitor,make_clean_names)
importFrom(lifecycle,badge)
importFrom(lifecycle,deprecated)
importFrom(lifecycle,signal_stage)
importFrom(purrr,discard)
importFrom(purrr,map)
importFrom(purrr,map_dfr)
importFrom(purrr,map_lgl)
importFrom(purrr,walk)
importFrom(purrr,walk2)
importFrom(rlang,.data)
Expand Down
8 changes: 7 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
<!-- NEWS.md is maintained by https://cynkra.github.io/fledge, do not edit -->
# sfext development

* Deprecate `get_data_dir()` function (superseded by) `filenamr::get_data_dir()`.
* Removed `write_exif()` function (moved to `filenamr::write_exif()`).
* Replace null.ok parameter with allow_null and list.ok parameter with allow_list.
* Stop importing `purrr::map()` and `purrr::map_lgl()` (replaced with `standalone-purrr.R`).
* Add new pkg parameter to `read_sf_pkg()` as alternative to package parameter.

# sfext 0.1.0.9000 (2023-03-15)

Expand Down
7 changes: 3 additions & 4 deletions R/as_point.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#' @details Using as_points:
#'
#' [as_points()] always returns an sfc object. The parameters are passed to
#' as_point using [purrr::map] and then converted to sfc using
#' as_point using [purrr::map()] and then converted to sfc using
#' [sf::st_as_sfc()]. The ... parameters must include a crs, otherwise the crs
#' will be NA for the resulting sfc object.
#'
Expand Down Expand Up @@ -63,7 +63,6 @@ as_point <- function(..., to = "POINT") {
#' @rdname as_point
#' @name as_points
#' @export
#' @importFrom purrr map
#' @importFrom sf st_as_sfc st_cast
as_points <- function(..., to = "POINT", call = caller_env()) {
params <- list2(...)
Expand Down Expand Up @@ -223,7 +222,7 @@ as_lines <- function(..., to = "LINESTRING") {
#' @name as_polygons
#' @rdname as_point
#' @export
#' @importFrom purrr map_dfr map_lgl
#' @importFrom purrr map_dfr
as_polygons <- function(..., to = "POLYGON") {
params <- list2(...)
crs <- NULL
Expand All @@ -234,7 +233,7 @@ as_polygons <- function(..., to = "POLYGON") {
crs <- sf::st_crs(params[[1]])
}

if (all(purrr::map_lgl(params, ~ is_polygon(.x)))) {
if (all(map_lgl(params, ~ is_polygon(.x)))) {
return(purrr::map_dfr(params, ~ as_sf(.x)))
}

Expand Down
2 changes: 1 addition & 1 deletion R/as_sf.R
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ make_sf_grid_list <- function(x, style = "rect", ncol = 2, nrow = 2, .id = "grid
#' @rdname as_sf
#' @export
as_sf_class <- function(x, class = NULL, allow_null = TRUE, call = caller_env(), ...) {
if (is.null(class) && allow_null) {
if (is.null(class) && is_true(allow_null)) {
return(x)
}

Expand Down
1 change: 0 additions & 1 deletion R/get_coords.R
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ get_coords <- function(x,
#' @aliases st_coords_minmax
#' @rdname get_coords
#' @importFrom dplyr mutate row_number select bind_cols
#' @importFrom purrr map
#' @importFrom tibble enframe
#' @importFrom sf st_drop_geometry
get_minmax <- function(x, crs = NULL, keep_all = TRUE, drop = TRUE) {
Expand Down
16 changes: 8 additions & 8 deletions R/is_sf.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#' @param ext If `TRUE`, check if x is a `sf`, `sfc`, or `bbox` class object or
#' not; defaults to `FALSE`. (used by [is_sf])
#' @param allow_null If `TRUE` and x is `NULL`, return `TRUE`; defaults to `FALSE`.
#' @param list.ok If `TRUE`, [is_sf] will return TRUE if x is a list of sf objects.
#' @param allow_list If `TRUE`, [is_sf] will return TRUE if x is a list of sf objects.
#' @details
#' - [is_sf]: is x a `sf` class object?
#' - [is_sfc]: is x is a `sfc` class object?
Expand All @@ -19,7 +19,7 @@
#'
#' @export
#' @md
is_sf <- function(x, ext = FALSE, allow_null = FALSE, list.ok = FALSE) {
is_sf <- function(x, ext = FALSE, allow_null = FALSE, allow_list = FALSE) {
classes <- "sf"

if (isTRUE(ext)) {
Expand All @@ -28,7 +28,7 @@ is_sf <- function(x, ext = FALSE, allow_null = FALSE, list.ok = FALSE) {
classes <- c(classes, ext)
}

if (!list.ok) {
if (isFALSE(allow_list)) {
return(is_class(x, classes = classes, allow_null = allow_null))
}

Expand Down Expand Up @@ -61,7 +61,7 @@ is_bbox <- function(x, allow_null = FALSE) {
#' @param named If `TRUE`, check if sf list is named; defaults `FALSE`.
#' @export
is_sf_list <- function(x, named = FALSE, ext = FALSE, allow_null = FALSE) {
if (is.null(x) && allow_null) {
if (is.null(x) && isTRUE(allow_null)) {
return(TRUE)
}

Expand All @@ -80,11 +80,11 @@ is_sf_list <- function(x, named = FALSE, ext = FALSE, allow_null = FALSE) {
)
)

if (!named) {
if (isFALSE(named)) {
return(is_sf_list)
}

is_sf_list && is_named(x)
isTRUE(is_sf_list) && is_named(x)
}

#' @name is_raster
Expand All @@ -98,7 +98,7 @@ is_raster <- function(x, allow_null = FALSE) {
#' @rdname is_sf
#' @export
is_sp <- function(x, allow_null = FALSE) {
if (is.null(x) && allow_null) {
if (is.null(x) && isTRUE(allow_null)) {
return(TRUE)
}

Expand All @@ -109,7 +109,7 @@ is_sp <- function(x, allow_null = FALSE) {
#' @rdname is_sf
#' @export
is_geo_coords <- function(x, allow_null = FALSE) {
if (is.null(x) && allow_null) {
if (is.null(x) && isTRUE(allow_null)) {
return(TRUE)
}

Expand Down
Loading

0 comments on commit 411357a

Please sign in to comment.