Skip to content

Commit

Permalink
refactor: update to work w/ new isstatic functions
Browse files Browse the repository at this point in the history
- refactor: update to work w/ new isstatic functions
- refactor: swap is_pkg_installed for rlang::check_installed
  • Loading branch information
elipousson committed Jan 18, 2023
1 parent 1e4278c commit b96fd0b
Show file tree
Hide file tree
Showing 15 changed files with 196 additions and 106 deletions.
5 changes: 0 additions & 5 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,6 @@ importFrom(dplyr,summarize)
importFrom(dplyr,tibble)
importFrom(filenamr,check_file_overwrite)
importFrom(filenamr,make_filename)
importFrom(filenamr,str_add_fileext)
importFrom(filenamr,str_extract_fileext)
importFrom(glue,glue)
importFrom(glue,glue_collapse)
importFrom(janitor,clean_names)
Expand Down Expand Up @@ -260,9 +258,6 @@ importFrom(sf,st_transform)
importFrom(sf,st_union)
importFrom(sf,st_zm)
importFrom(sf,write_sf)
importFrom(stringr,str_detect)
importFrom(stringr,str_extract)
importFrom(stringr,str_remove)
importFrom(tibble,enframe)
importFrom(units,as_units)
importFrom(units,drop_units)
Expand Down
4 changes: 2 additions & 2 deletions R/as_sf.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ as_bbox <- function(x, crs = NULL, ext = TRUE, ...) {
}

if (is.character(x) && rlang::has_length(x, 1)) {
is_pkg_installed("osmdata")
rlang::check_installed("osmdata")
x <- osmdata::getbb(x, format_out = "matrix", ...)
stopifnot(
!any(is.na(x))
Expand Down Expand Up @@ -338,7 +338,7 @@ pluck_len1 <- function(x) {
#'
#' @noRd
as_start_end_points <- function(x, crs = 4326, class = "data.frame") {
is_pkg_installed("lwgeom")
rlang::check_installed("lwgeom")

if (!is_line(x)) {
x <- as_line(x)
Expand Down
10 changes: 7 additions & 3 deletions R/bind_units_col.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@
#' error messages when function is used internally.
#' @export
#' @importFrom dplyr bind_cols
bind_units_col <- function(x, y, units = NULL, drop = FALSE, keep_all = TRUE, .id = NULL, call = caller_env()) {
is_pkg_installed("units")

bind_units_col <- function(x,
y,
units = NULL,
drop = FALSE,
keep_all = TRUE,
.id = NULL,
call = caller_env()) {
if (!is.null(units)) {
y <-
convert_dist_units(
Expand Down
4 changes: 2 additions & 2 deletions R/coords_to_sf.R
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,8 @@ format_coords <- function(x,
separate_coords <- function(x, coords, into = c("lon", "lat"), sep = ",") {
into <- check_coords(x = NULL, coords = into)

is_pkg_installed("readr")
is_pkg_installed("tidyr")
rlang::check_installed("readr")
rlang::check_installed("tidyr")

x <-
tidyr::separate(
Expand Down
2 changes: 1 addition & 1 deletion R/count_sf_ext.R
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ count_sf_ext <- function(data,
)

if (replace_na) {
is_pkg_installed("tidyr")
rlang::check_installed("tidyr")
data_count <- tidyr::replace_na(data_count, rlang::set_names(list(0), name))
} else if (!keep_na) {
data_count <- dplyr::filter(data_count, !is.na(.data[[name]]))
Expand Down
2 changes: 1 addition & 1 deletion R/get_coords.R
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ get_minmax <- function(x, crs = NULL, keep_all = TRUE, drop = TRUE) {

x <- dplyr::select(x, -.data[[col]])

is_pkg_installed("tidyr")
rlang::check_installed("tidyr")

minmax_df <-
tidyr::unnest_wider(
Expand Down
5 changes: 2 additions & 3 deletions R/get_data_dir.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ get_data_dir <- function(path = NULL,
pkg = "sfext",
null.ok = TRUE) {
if (cache) {
is_pkg_installed("rappdirs")
rlang::check_installed("rappdirs")
path <- path %||% rappdirs::user_cache_dir(pkg)
}

Expand Down Expand Up @@ -64,7 +64,6 @@ get_data_dir <- function(path = NULL,
#' @param n Max number of unique file types to return. Returns warning and n
#' most common file types if path has more than n unique file types.
#' @noRd
#' @importFrom stringr str_extract
get_path_filetype <- function(path, filetype = NULL, n = 1) {
if (!is.null(filetype)) {
return(filetype)
Expand All @@ -82,7 +81,7 @@ get_path_filetype <- function(path, filetype = NULL, n = 1) {
)
}

filetype <- filenamr::str_extract_fileext(file_list)
filetype <- str_extract_fileext(file_list)

if (length(unique(filetype)) <= n) {
return(unique(filetype))
Expand Down
4 changes: 2 additions & 2 deletions R/read_sf_exif.R
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ read_sf_exif <- function(path = NULL,
tags = NULL,
geometry = TRUE,
...) {
is_pkg_installed("exiftoolr")
rlang::check_installed("exiftoolr")

# FIXME: This is a partial list of filetypes that support GPS EXIF metadata
# filetype <- match.arg(filetype, c("jpg", "jpeg", "png", "tiff", "pdf"))
Expand Down Expand Up @@ -225,7 +225,7 @@ write_exif <- function(path,
args = NULL,
overwrite = TRUE,
append_keywords = FALSE) {
is_pkg_installed("exiftoolr")
rlang::check_installed("exiftoolr")

# FIXME: I want to implement a method that allows adding, replacing, or modifying exif
if (is.null(args)) {
Expand Down
36 changes: 17 additions & 19 deletions R/read_sf_ext.R
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ read_sf_pkg <- function(data,
...) {
check_null(package)

is_pkg_installed(package)
rlang::check_installed(package)

cli_abort_ifnot(
"{.arg data} must be a length 1 character vector with
Expand All @@ -173,7 +173,7 @@ read_sf_pkg <- function(data,
}

# FIXME: This triggers an alert with lintr but works fine
filename <- filenamr::str_add_fileext(data, fileext = filetype)
filename <- str_add_fileext(data, fileext = filetype)

path <-
dplyr::case_when(
Expand Down Expand Up @@ -205,9 +205,9 @@ read_sf_path <- function(path, bbox = NULL, ...) {

type <-
dplyr::case_when(
is_csv_path(path) ~ "csv",
is_excel_path(path) ~ "excel",
is_rdata_path(path) ~ "rdata",
is_csv_fileext(path) ~ "csv",
is_excel_fileext(path) ~ "excel",
is_rdata_fileext(path) ~ "rdata",
TRUE ~ "query"
)

Expand All @@ -233,12 +233,12 @@ read_sf_rdata <- function(path,

type <-
dplyr::case_when(
is_rds_path(file) ~ "rds",
is_rdata_path(file) ~ "rdata"
is_rds_fileext(file) ~ "rds",
is_rdata_fileext(file) ~ "rdata"
)

if (type == "rds") {
is_pkg_installed("readr")
rlang::check_installed("readr")
data <- readr::read_rds(file, refhook = refhook)
} else {
file_name <- load(file)
Expand Down Expand Up @@ -270,7 +270,6 @@ read_sf_rdata <- function(path,
#' available table names.
#' @param .name_repair Passed to repair parameter of [vctrs::vec_as_names()]
#' @export
#' @importFrom stringr str_extract
#' @importFrom sf st_layers read_sf st_zm
#' @importFrom rlang is_lambda as_function is_function set_names
read_sf_query <- function(path,
Expand Down Expand Up @@ -335,7 +334,7 @@ read_sf_excel <- function(path,
address = "address",
.name_repair = "check_unique",
...) {
is_pkg_installed("readxl")
rlang::check_installed("readxl")
# Convert XLS or XLSX file with coordinates to sf

sheet <- sheet %||% readxl::excel_sheets(path)
Expand Down Expand Up @@ -416,7 +415,7 @@ read_sf_csv <- function(path,
}

if (show_col_types) {
is_pkg_installed("readr")
rlang::check_installed("readr")
data <-
readr::read_csv(
file = path,
Expand Down Expand Up @@ -470,7 +469,6 @@ read_sf_csv <- function(path,
#' @rdname read_sf_ext
#' @param zm_drop If `TRUE`, drop Z and/or M dimensions using [sf::st_zm]
#' @export
#' @importFrom stringr str_detect
#' @importFrom sf read_sf st_zm
#' @importFrom dplyr case_when
read_sf_url <- function(url,
Expand All @@ -486,13 +484,13 @@ read_sf_url <- function(url,

url_type <-
dplyr::case_when(
is_csv_path(url) ~ "csv",
is_excel_path(url) ~ "excel",
is_csv_fileext(url) ~ "csv",
is_excel_fileext(url) ~ "excel",
is_esri_url(url) ~ "esri",
is_gist_url(url) ~ "gist",
is_gmap_url(url) ~ "gmap",
is_gsheet_url(url) ~ "gsheet",
is_rds_path(url) ~ "rds",
is_rds_fileext(url) ~ "rds",
!is.null(params$filename) ~ "download",
TRUE ~ "other"
)
Expand Down Expand Up @@ -665,7 +663,7 @@ read_sf_gist <- function(url,
bbox = NULL,
nth = 1,
...) {
is_pkg_installed("gistr")
rlang::check_installed("gistr")

if (!is_missing(url) && is.null(id)) {
id <- url
Expand Down Expand Up @@ -750,7 +748,7 @@ read_sf_gmap <- function(url,
)

if (has_name(data, "Description")) {
is_pkg_installed("naniar")
rlang::check_installed("naniar")
data <- naniar::replace_with_na(data, replace = list("Description" = ""))
}

Expand Down Expand Up @@ -870,7 +868,7 @@ read_sf_gsheet <- function(url,
.name_repair = "check_unique",
...) {
# Convert Google Sheet with coordinates to sf
is_pkg_installed("googlesheets4")
rlang::check_installed("googlesheets4")

if (ask) {
ss <-
Expand Down Expand Up @@ -1007,7 +1005,7 @@ make_sf_query <- function(dsn = NULL,
name = NULL,
name_col = NULL,
query = NULL) {
if (any(c(is.null(name), is.null(name_col), is_geojson_path(dsn)))) {
if (any(c(is.null(name), is.null(name_col), is_geojson_fileext(dsn)))) {
return(query %||% NA)
}

Expand Down
2 changes: 1 addition & 1 deletion R/sf_to_df.R
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ address_to_sf <- function(x,
crs = NULL,
full_results = FALSE,
...) {
is_pkg_installed("tidygeocoder")
rlang::check_installed("tidygeocoder")

if (is.character(x)) {
# Make vector into address column
Expand Down
2 changes: 1 addition & 1 deletion R/sfext-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

## usethis namespace: start
#' @import rlang
#' @importFrom rlang .data .env caller_env has_length is_interactive
#' @importFrom rlang .data .env caller_env has_length is_interactive check_installed
#' @importFrom cli cli_abort cli_warn cli_inform
#' @importFrom cliExtras cli_abort_ifnot cli_warn_ifnot cli_yesno
#' @importFrom glue glue glue_collapse
Expand Down
2 changes: 1 addition & 1 deletion R/st_concave_hull.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ st_concave_hull <- function(x,
centroid = FALSE,
concavity = 2,
length_threshold = 0) {
is_pkg_installed("concaveman")
rlang::check_installed("concaveman")

check_sf(x)

Expand Down
Loading

0 comments on commit b96fd0b

Please sign in to comment.