diff --git a/R/distance_to_leader.R b/R/distance_to_leader.R index ff389fe4..e48024e4 100644 --- a/R/distance_to_leader.R +++ b/R/distance_to_leader.R @@ -13,7 +13,7 @@ #' \code{\link[data.table:setDT]{data.table::setDT}} or by reassigning using #' \code{\link[data.table:data.table]{data.table::data.table}}. #' -#' This function expects a \code{rank_dist_along_group_bearing} column +#' This function expects a \code{rank_position_group_direction} column #' generated with \code{leader_direction_group(return_rank = TRUE)}, #' a \code{group} column generated with the #' \code{group_pts} function. The \code{coords} and \code{group} arguments @@ -79,15 +79,15 @@ distance_to_leader <- function(DT, coords = c('x', 'y'), group = 'group') { stopifnot(first(coords) %in% colnames(DT)) stopifnot(last(coords) %in% colnames(DT)) stopifnot(group %in% colnames(DT)) - stopifnot('rank_dist_along_group_bearing' %in% colnames(DT)) + stopifnot('rank_position_group_direction' %in% colnames(DT)) DT[, temp_N_by_group := .N, by = c(group)] - check_has_leader <- DT[, .(has_leader = any(rank_dist_along_group_bearing == 1)), + check_has_leader <- DT[, .(has_leader = any(rank_position_group_direction == 1)), by = c(group)][!(has_leader)] if (check_has_leader[, .N > 0]) { - warning('groups found missing leader (rank_dist_along_group_bearing == 1): \n', + warning('groups found missing leader (rank_position_group_direction == 1): \n', check_has_leader[, paste(group, collapse = ', ')]) } @@ -97,7 +97,7 @@ distance_to_leader <- function(DT, coords = c('x', 'y'), group = 'group') { as.matrix(dist(cbind(.SD[[1]], .SD[[2]])))[, which(.SD[[3]] == 1)], 0 ), - .SDcols = c(coords, 'rank_dist_along_group_bearing'), + .SDcols = c(coords, 'rank_position_group_direction'), by = c(group)] DT[, temp_N_by_group := NULL] return(DT)