Skip to content

Commit

Permalink
fix expected colname
Browse files Browse the repository at this point in the history
  • Loading branch information
robitalec committed Oct 31, 2024
1 parent 7546458 commit 1d0c7c4
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions R/distance_to_leader.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = ', ')])
}

Expand All @@ -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)
Expand Down

0 comments on commit 1d0c7c4

Please sign in to comment.