Skip to content

Commit

Permalink
refactor: add rlang type checks to as_sf_list
Browse files Browse the repository at this point in the history
- refactor: add rlang type checks to as_sf_list + update imports
  • Loading branch information
elipousson committed Mar 15, 2023
1 parent 62d04b2 commit 8a90cbf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ importFrom(rlang,is_missing)
importFrom(rlang,is_named)
importFrom(rlang,list2)
importFrom(rlang,set_names)
importFrom(rlang,try_fetch)
importFrom(sf,NA_crs_)
importFrom(sf,read_sf)
importFrom(sf,st_area)
Expand Down
7 changes: 5 additions & 2 deletions R/as_sf.R
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,7 @@ as_sfc <- function(x, crs = NULL, ext = TRUE, ...) {
#' @importFrom janitor make_clean_names
as_sf_list <- function(x, nm = "data", col = NULL, crs = NULL, clean_names = TRUE) {
check_null(x)
check_character(col, null.ok = TRUE)
check_len(col, len = 1, null.ok = TRUE)
check_string(col, allow_null = TRUE)

if (!is_sf_list(x, ext = TRUE)) {
# data frame with nested list column named data
Expand Down Expand Up @@ -239,6 +238,7 @@ as_sf_list <- function(x, nm = "data", col = NULL, crs = NULL, clean_names = TRU
#' @inheritParams st_make_grid_ext
#' @inheritParams as_sf_list
#' @export
#' @importFrom dplyr mutate
make_sf_grid_list <- function(x, style = "rect", ncol = 2, nrow = 2, .id = "grid_id", crs = NULL, ...) {
grid <- st_make_grid_ext(x, style = style, ncol = ncol, nrow = nrow, .id = .id, ...)

Expand Down Expand Up @@ -298,6 +298,9 @@ as_sf_class <- function(x, class = NULL, null.ok = TRUE, call = caller_env(), ..
#' @param check For `as_crs()`, if `TRUE`, error if crs cannot be converted to a
#' valid coordinate reference system. Defaults to `FALSE`.
#' @export
#' @importFrom rlang try_fetch
#' @importFrom sf st_crs
#' @importFrom cli cli_alert_warning cli_abort
as_crs <- function(crs = NULL, check = FALSE, call = parent.frame()) {
rlang::try_fetch(
sf::st_crs(crs),
Expand Down

0 comments on commit 8a90cbf

Please sign in to comment.