From bce07b68921232deee2f4eb0d47a731f70be4afa Mon Sep 17 00:00:00 2001 From: Eli Pousson Date: Mon, 25 Jul 2022 13:06:23 -0400 Subject: [PATCH] docs: fill missing parameter definitions --- R/as_sf.R | 6 ++++++ R/count_features.R | 8 ++++---- R/read_sf_ext.R | 11 +++++++++++ R/utils-filename.R | 2 ++ man/as_sf.Rd | 8 ++++++++ man/count_features.Rd | 3 +++ man/read_sf_ext.Rd | 17 ++++++++++++++--- man/str_misc.Rd | 3 +++ 8 files changed, 51 insertions(+), 7 deletions(-) diff --git a/R/as_sf.R b/R/as_sf.R index 519e631..c04c9d6 100644 --- a/R/as_sf.R +++ b/R/as_sf.R @@ -10,6 +10,10 @@ #' [as_sf_list()] only supports sf objects or a data frames with a sf list #' column named "data" (typically created by using [dplyr::group_nest()] on an #' sf object. +#' @param ext If `TRUE`, [as_sf] will convert a data frame or character vector +#' of addresses to an sf object using [df_to_sf] or [address_to_sf]. If +#' `FALSE`, only spatial objects (bbox, sfg, sfc, sf list, raster, or sp +#' objects) can be converted. Defaults to `TRUE`. #' @param sf_col A column name to use for the geometry column created by #' [as_sf]; defaults to "geometry". #' @param crs Coordinate reference system for `sf`, `bbox`, `sfc` or `sf` list @@ -198,6 +202,8 @@ as_sf_list <- function(x, nm = "data", col = NULL, crs = NULL, clean_names = TRU #' @param data Data that can be converted to sf, sfc, bbox or a sf list object. #' @param class A class to convert data to; defaults to NULL (which returns #' "sf") +#' @param null.ok For [as_sf_class], if class is `NULL` and null.ok is `TRUE`, +#' return x without any class conversion or checks. Defaults to `TRUE`. #' @param ... Additional parameters passed to [as_sf], [as_sfc], [as_bbox], or #' [as_sf_list] #' @name as_sf_class diff --git a/R/count_features.R b/R/count_features.R index 0f8cf4c..7d7464d 100644 --- a/R/count_features.R +++ b/R/count_features.R @@ -7,6 +7,8 @@ #' @param y Length 1 named `sf` list (name of y is used as count if count is #' `NULL`) or a `sf` object if nm is not `NULL`. y must include a column name #' matching the value of .id. If y is `NULL`, count is required. Default: `NULL` +#' @param nm Vector of names to use with [as_sf_list] to convert y to an sf list +#' (if y is not already an sf list). Defaults to "data". #' @inheritParams st_join_ext #' @inheritParams df_to_sf #' @param count Name of column to count. If `NULL`, count is set to `names(y)` @@ -46,9 +48,7 @@ count_features <- function(x = NULL, x <- st_join_ext(x, y, join = join, .id = .id, ...) - if (is.null(count)) { - count <- names(y) - } + count <- count %||% names(y) # Convert y back into a sf object y <- as_sf(y) @@ -70,7 +70,7 @@ count_features <- function(x = NULL, geometry <- arg_match(geometry, c("y", "x", "drop")) - if (!is_sf(y) | (geometry == "x")) { + if (!is_sf(y) || (geometry == "x")) { return(x) } diff --git a/R/read_sf_ext.R b/R/read_sf_ext.R index 32675af..87dddda 100644 --- a/R/read_sf_ext.R +++ b/R/read_sf_ext.R @@ -230,6 +230,16 @@ read_sf_rdata <- function(path, #' @name read_sf_query #' @rdname read_sf_ext #' @inheritParams sf::read_sf +#' @param name,name_col Name value and name column to use in generated a query +#' for sources read with [read_sf_query] or [read_sf_esri]. This same +#' convention is used by [getdata::get_location] which wraps +#' sfext::read_sf_ext allowing the use of these parameters with any +#' [read_sf_ext] function. This option for filtering may be added to more +#' read_sf_ext functions in the future. +#' @param table table can usually be inferred from basename of the data source. +#' table is used to generate a custom query if both name and name_col are +#' provided. Use `sf::st_layers(dsn = dsn)[["name"]]` to see a list of +#' available table names. #' @export #' @importFrom stringr str_extract #' @importFrom sf read_sf st_zm @@ -482,6 +492,7 @@ read_sf_url <- function(url, #' @name read_sf_esri #' @rdname read_sf_ext +#' @inheritParams esri2sf::esri2sf #' @export read_sf_esri <- function(url, bbox = NULL, diff --git a/R/utils-filename.R b/R/utils-filename.R index 6351270..eb3221f 100644 --- a/R/utils-filename.R +++ b/R/utils-filename.R @@ -124,6 +124,8 @@ str_remove_filetype <- function(string, filetype = NULL) { #' @name str_extract_filetype #' @rdname str_misc +#' @param tocase Function to use with [str_extract_filetype] for case conversion +#' of returned filetype. Defaults to [tolower()]. #' @export str_extract_filetype <- function(string, filetype = NULL, tocase = tolower) { filetype <- filetype %||% "[a-zA-Z0-9]+" diff --git a/man/as_sf.Rd b/man/as_sf.Rd index 11955f9..cae0110 100644 --- a/man/as_sf.Rd +++ b/man/as_sf.Rd @@ -32,6 +32,11 @@ object to return.} \item{sf_col}{A column name to use for the geometry column created by \link{as_sf}; defaults to "geometry".} +\item{ext}{If \code{TRUE}, \link{as_sf} will convert a data frame or character vector +of addresses to an sf object using \link{df_to_sf} or \link{address_to_sf}. If +\code{FALSE}, only spatial objects (bbox, sfg, sfc, sf list, raster, or sp +objects) can be converted. Defaults to \code{TRUE}.} + \item{...}{Additional parameters passed to \link{as_sf}, \link{as_sfc}, \link{as_bbox}, or \link{as_sf_list}} @@ -48,6 +53,9 @@ provided.} \item{class}{A class to convert data to; defaults to NULL (which returns "sf")} +\item{null.ok}{For \link{as_sf_class}, if class is \code{NULL} and null.ok is \code{TRUE}, +return x without any class conversion or checks. Defaults to \code{TRUE}.} + \item{call}{Passed as the call parameter for \link[cli:cli_abort]{cli::cli_abort} or \link[rlang:arg_match]{rlang::arg_match} to improve error messages when function is used internally.} diff --git a/man/count_features.Rd b/man/count_features.Rd index b40235c..cd289bd 100644 --- a/man/count_features.Rd +++ b/man/count_features.Rd @@ -25,6 +25,9 @@ count_features( \code{NULL}) or a \code{sf} object if nm is not \code{NULL}. y must include a column name matching the value of .id. If y is \code{NULL}, count is required. Default: \code{NULL}} +\item{nm}{Vector of names to use with \link{as_sf_list} to convert y to an sf list +(if y is not already an sf list). Defaults to "data".} + \item{join}{geometry predicate function; defaults to \code{NULL}, set to \link[sf:geos_binary_pred]{sf::st_intersects} if key_list contains only POLYGON or MULTIPOLYGON objects or \link[sf:st_nearest_feature]{sf::st_nearest_feature} if key_list contains other types.} diff --git a/man/read_sf_ext.Rd b/man/read_sf_ext.Rd index 98f9e1c..e96a9f5 100644 --- a/man/read_sf_ext.Rd +++ b/man/read_sf_ext.Rd @@ -130,9 +130,17 @@ also be an open database connection.} \item{query}{SQL query to select records; see details} -\item{name}{Name to make file name converted to snake case with -\code{\link[janitor:make_clean_names]{janitor::make_clean_names()}}, e.g. "Residential zoning map" becomes -"residential_zoning_map"} +\item{table}{table can usually be inferred from basename of the data source. +table is used to generate a custom query if both name and name_col are +provided. Use \code{sf::st_layers(dsn = dsn)[["name"]]} to see a list of +available table names.} + +\item{name, name_col}{Name value and name column to use in generated a query +for sources read with \link{read_sf_query} or \link{read_sf_esri}. This same +convention is used by \link[getdata:get_location]{getdata::get_location} which wraps +sfext::read_sf_ext allowing the use of these parameters with any +\link{read_sf_ext} function. This option for filtering may be added to more +read_sf_ext functions in the future.} \item{wkt_filter}{character; WKT representation of a spatial filter (may be used as bounding box, selecting overlapping geometries); see examples} @@ -162,6 +170,9 @@ ArcGIS FeatureServer or MapServer to access with \code{\link[esri2sf:esri2sf]{es (the default) only show the column types if they are not explicitly supplied by the \code{col_types} argument.} +\item{where}{string for where condition. Default is \code{NULL} (equivalent to +\code{1=1}) to return all rows.} + \item{id}{The name of a column in which to store the file path. This is useful when reading multiple input files and there is data in the file paths, such as the data collection date. If \code{NULL} (the default) no extra diff --git a/man/str_misc.Rd b/man/str_misc.Rd index c2662e9..39c0b9f 100644 --- a/man/str_misc.Rd +++ b/man/str_misc.Rd @@ -72,6 +72,9 @@ prefix is "date" or "time" and not currently accessible when using \item{filetype}{File type string} +\item{tocase}{Function to use with \link{str_extract_filetype} for case conversion +of returned filetype. Defaults to \code{\link[=tolower]{tolower()}}.} + \item{side}{Side on which padding character is added (left, right or both).} } \description{