diff --git a/NAMESPACE b/NAMESPACE index 2df1349..28c090e 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -4,8 +4,8 @@ S3method(ext_matrix,SpatExtent) S3method(ext_matrix,SpatRaster) S3method(ext_matrix,SpatVector) S3method(ext_matrix,default) +S3method(ext_matrix,double) S3method(ext_matrix,matrix) -S3method(ext_matrix,vector) export(calculate_travel_time) export(ext_from_terra) export(ext_matrix) diff --git a/R/ext_matrix.R b/R/ext_matrix.R index cbc4e44..5ff4e3a 100644 --- a/R/ext_matrix.R +++ b/R/ext_matrix.R @@ -1,43 +1,41 @@ #' @title Convert extent to matrix #' #' @description -#' This function converts from formats ... -#' TODO - explain why we need to do this, which is that we need a special esoteric format +#' This function allows `get_friction_surface()` to accept the argument `extent` as a `vector`, 2x2 `matrix`, `SpatVector`, or `SpatRaster` and extracts and converts into the annoyingly specific format necessary to download the friction surface. See details in `?get_friction_surface` #' -#' @param x `numeric` length 4, consisting of `c(xmin, xmax, ymin, ymax)` -#' dimensions of extent +#' @param extent `vector` of length 4, 2x2 `matrix`, `SpatVector`, or `SpatRaster` #' -#' @return 2x2 `matrix` - explain esoteric format of matrix +#' @return 2x2 `matrix` with column names "x" and "y" and row names "min" +#' and "max #' #' @examples #' ext_matrix(c(111,112,0, 1)) -#' # TODO -#' # add examples of all SpatRaster, SpatVector, etc. +#' #' @export -ext_matrix <- function(x, ...){ +ext_matrix <- function(extent){ UseMethod("ext_matrix") } #' @export -ext_matrix.SpatExtent <- function(x, ...){ - extent <- ext_vect_to_matrix(x) +ext_matrix.SpatExtent <- function(extent){ + extent <- ext_vect_to_matrix(extent) extent } #' @export -ext_matrix.SpatRaster <- function(x, ...){ - extent <- ext_from_terra(x) +ext_matrix.SpatRaster <- function(extent){ + extent <- ext_from_terra(extent) extent } #' @export -ext_matrix.SpatVector <- function(x, ...){ - extent <- ext_from_terra(x) +ext_matrix.SpatVector <- function(extent){ + extent <- ext_from_terra(extent) extent } #' @export -ext_matrix.vector <- function(x){ +ext_matrix.double <- function(extent){ if (length(extent) != 4){ cli::cli_abort( message = c( @@ -46,33 +44,32 @@ ext_matrix.vector <- function(x){ ) ) } - extent <- ext_vect_to_matrix(x) + extent <- ext_vect_to_matrix(extent) extent } #' @export -ext_matrix.matrix <- function(x, ...){ - is_2x2 <- identical(dim(x), c(2L,2L)) +ext_matrix.matrix <- function(extent){ + is_2x2 <- identical(dim(extent), c(2L,2L)) if(!is_2x2){ cli::cli_abort( message = c( - "If {.arg x} is of class, {.cls matrix}, it must have dimensions: 2x2", + "If {.arg extent} is of class, {.cls matrix}, it must have dimensions: 2x2", "However, we see that {.arg x} has dimensions: \\ - {.val {paste0(dim(x), collapse = 'x')}}." + {.val {paste0(dim(extent), collapse = 'x')}}." ) ) } - extent <- x extent } #' @export -ext_matrix.default <- function(x, ...){ +ext_matrix.default <- function(extent){ cli::cli_abort( message = c( "{.arg extent} must be of class {.cls numeric, matrix, \\ - SpatExtent, SpatRaster}", - "But we see class: {.cls {class(x)}." + SpatExtent, SpatRaster, SpatVector}", + "But we see class: {.cls {class(extent)}}." ) ) } diff --git a/man/ext_matrix.Rd b/man/ext_matrix.Rd index 41f3887..0331c9e 100644 --- a/man/ext_matrix.Rd +++ b/man/ext_matrix.Rd @@ -4,21 +4,19 @@ \alias{ext_matrix} \title{Convert extent to matrix} \usage{ -ext_matrix(x, ...) +ext_matrix(extent) } \arguments{ -\item{x}{\code{numeric} length 4, consisting of \code{c(xmin, xmax, ymin, ymax)} -dimensions of extent} +\item{extent}{\code{vector} of length 4, 2x2 \code{matrix}, \code{SpatVector}, or \code{SpatRaster}} } \value{ -2x2 \code{matrix} - explain esoteric format of matrix +2x2 \code{matrix} with column names "x" and "y" and row names "min" +and "max } \description{ -This function converts from formats ... -TODO - explain why we need to do this, which is that we need a special esoteric format +This function allows \code{get_friction_surface()} to accept the argument \code{extent} as a \code{vector}, 2x2 \code{matrix}, \code{SpatVector}, or \code{SpatRaster} and extracts and converts into the annoyingly specific format necessary to download the friction surface. See details in \code{?get_friction_surface} } \examples{ ext_matrix(c(111,112,0, 1)) -# TODO -# add examples of all SpatRaster, SpatVector, etc. + } diff --git a/man/traveltime-package.Rd b/man/traveltime-package.Rd index 90c350a..8e63b63 100644 --- a/man/traveltime-package.Rd +++ b/man/traveltime-package.Rd @@ -26,7 +26,7 @@ Authors: Other contributors: \itemize{ - \item Nicholas Tierney (\href{https://orcid.org/0000-0000-0000-0000}{ORCID}) [contributor] + \item Nicholas Tierney \email{nicholas.tierney@gmail.com} (\href{https://orcid.org/0000-0003-1460-8722}{ORCID}) [contributor] } } diff --git a/traveltime.Rproj b/traveltime.Rproj index 497f8bf..2f92160 100644 --- a/traveltime.Rproj +++ b/traveltime.Rproj @@ -1,4 +1,5 @@ Version: 1.0 +ProjectId: d7cb03ec-3557-4217-8f1a-4913ea040d41 RestoreWorkspace: Default SaveWorkspace: Default