Skip to content

Commit

Permalink
rename all slope_z_..() funcions to z_...() for more intuitive names.…
Browse files Browse the repository at this point in the history
… leave "slope_.." for funcions that deal with slope values - not elevation.

#32
temospena committed Aug 17, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 877b187 commit 44ee193
Showing 2 changed files with 23 additions and 23 deletions.
32 changes: 16 additions & 16 deletions R/z.R
Original file line number Diff line number Diff line change
@@ -9,63 +9,63 @@
#' @examples
#' x = slopes::lisbon_route_3d
#' sf::st_geometry(x)
#' slope_z_value(x)[1:5]
#' z_value(x)[1:5]
#' xy = slopes::lisbon_route
#' # slope_z_value(xy) # error message
#' slope_z_start(x)
#' slope_z_end(x)
slope_z_value = function(x) {
#' # z_value(xy) # error message
#' z_start(x)
#' z_end(x)
z_value = function(x) {
coords = sf::st_coordinates(x)
if(!"Z" %in% colnames(coords)) {
stop("Requires object that have XYZ geometries, see ?slope_raster.")
}
coords[, "Z"]
}
#' @rdname slope_z_value
#' @rdname z_value
#' @export
slope_z_start = function(x) {
z_start = function(x) {
coords = sf::st_coordinates(x)
if(!"Z" %in% colnames(coords)) {
stop("Requires object that have XYZ geometries, see ?slope_raster.")
}
coords[, "Z"][1]
}
#' @rdname slope_z_value
#' @rdname z_value
#' @export
slope_z_end = function(x) {
z_end = function(x) {
coords = sf::st_coordinates(x)
if(!"Z" %in% colnames(coords)) {
stop("Requires object that have XYZ geometries, see ?slope_raster.")
}
coords[, "Z"][nrow(coords)]
}
#' @rdname slope_z_value
#' @rdname z_value
#' @export
slope_z_mean = function(x) {
z_mean = function(x) {
coords = sf::st_coordinates(x)
if(!"Z" %in% colnames(coords)) {
stop("Requires object that have XYZ geometries, see ?slope_raster.")
}
mean(coords[, "Z"], na.rm = TRUE)
}
#' @rdname slope_z_value
#' @rdname z_value
#' @export
slope_z_max = function(x) {
z_max = function(x) {
coords = sf::st_coordinates(x)
if(!"Z" %in% colnames(coords)) {
stop("Requires object that have XYZ geometries, see ?slope_raster.")
}
max(coords[, "Z"])
}
#' @rdname slope_z_value
#' @rdname z_value
#' @export
slope_z_min = function(x) {
z_min = function(x) {
coords = sf::st_coordinates(x)
if(!"Z" %in% colnames(coords)) {
stop("Requires object that have XYZ geometries, see ?slope_raster.")
}
min(coords[, "Z"])
}
slope_z_direction = function(x) {
z_direction = function(x) {
# ...
}
14 changes: 7 additions & 7 deletions tests/testthat/test-z.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
test_that("Functions on Z values work", {
x = slopes::lisbon_route_3d
expect_equal(class(slope_z_value(x)), "numeric")
expect_equal(class(z_value(x)), "numeric")
x = slopes::lisbon_route
expect_error(slope_z_value(x))
expect_error(slope_z_start(x))
expect_error(slope_z_end(x))
expect_error(slope_z_mean(x))
expect_error(slope_z_max(x))
expect_error(slope_z_min(x))
expect_error(z_value(x))
expect_error(z_start(x))
expect_error(z_end(x))
expect_error(z_mean(x))
expect_error(z_max(x))
expect_error(z_min(x))
# x_slope =
# expect_is()
})

0 comments on commit 44ee193

Please sign in to comment.