Skip to content

Commit

Permalink
Document slope_vector() functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Robinlovelace committed Nov 9, 2020
1 parent 3f71fa5 commit 2738046
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 10 deletions.
4 changes: 3 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,7 @@ Suggests:
rmarkdown,
ceramic,
bookdown,
covr
covr,
testthat
VignetteBuilder: knitr
Config/testthat/edition: 3
21 changes: 16 additions & 5 deletions R/slopes.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
#' Calculate the gradient of line segments from distance and elevation vectors
#'
#' [slope_vector()] calculates the slopes associated with consecutive elements in one dimensional distance
#' and associated elevations (see examples).
#'
#' [slope_distance()] calculates the slopes associated with consecutive distances and elevations.
#'
#' [slope_distance_mean()] calculates the mean average slopes associated with consecutive distances and elevations.
#'
#' [slope_distance_weighted()] calculates the slopes associated with consecutive distances and elevations,
#' with the mean value associated with each set of distance/elevation vectors weighted in
#' proportion to the distance between each elevation measurement, so longer sections
#' have proportionally more influence on the resulting gradient estimate (see examples).
#'
#' @param x Vector of locations
#' @param d Vector of distances between points
#' @param e Elevations in same units as x (assumed to be metres)
Expand Down Expand Up @@ -27,17 +39,16 @@ slope_distance = function(d, e) {
}
#' @rdname slope_vector
#' @export
slope_distance_weighted = function(d, e) {
slope_distance_mean = function(d, e) {
e_change = diff(e)
stats::weighted.mean(abs(e_change) / d, d)
mean(abs(e_change) / d)
}
#' @rdname slope_vector
#' @export
slope_distance_mean = function(d, e) {
slope_distance_weighted = function(d, e) {
e_change = diff(e)
mean(abs(e_change) / d)
stats::weighted.mean(abs(e_change) / d, d)
}

#' Calculate the gradient of line segments from a 3D matrix of coordinates
#'
#' @param m Matrix containing coordinates and elevations
Expand Down
19 changes: 15 additions & 4 deletions man/slope_vector.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2738046

Please sign in to comment.