Skip to content

Commit

Permalink
Merge pull request #25 from ropensci/bug/edge-names-error
Browse files Browse the repository at this point in the history
fix edge_dist and edge_nn names warnings+error
  • Loading branch information
robitalec committed Mar 2, 2020
2 parents 3690be6 + f8e0380 commit 75042b8
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 12 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: spatsoc
Title: Group Animal Relocation Data by Spatial and Temporal Relationship
Version: 0.1.11
Version: 0.1.12
Authors@R:
c(person(given = "Alec L.",
family = "Robitaille",
Expand Down
6 changes: 5 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# v 0.1.12 (2020-03-02)
* fixed `data.table` error in `edge_dist` and `edge_nn` ([PR 25](https://github.com/ropensci/spatsoc/pull/25))


# v 0.1.11 (2020-02-20)
* removed default NULL from 'timegroup' arguments in `group_pts`, `edge_dist` and `edge_nn` ([PR 21](https://github.com/ropensci/spatsoc/pull/24))
* removed default NULL from 'timegroup' arguments in `group_pts`, `edge_dist` and `edge_nn` ([PR 24](https://github.com/ropensci/spatsoc/pull/24))


# v 0.1.10 (2019-06-06)
Expand Down
12 changes: 7 additions & 5 deletions R/edge_dist.R
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,18 @@ edge_dist <- function(DT = NULL,
distMatrix <-
as.matrix(stats::dist(.SD[, 2:3], method = 'euclidean'))
diag(distMatrix) <- NA

w <- which(distMatrix < threshold, arr.ind = TRUE)

if (returnDist) {
list(ID1 = .SD[[1]][w[, 1]],
ID2 = .SD[[1]][w[, 2]],
distance = distMatrix[w])
l <- list(ID1 = .SD[[1]][w[, 1]],
ID2 = .SD[[1]][w[, 2]],
distance = distMatrix[w])
} else {
list(ID1 = .SD[[1]][w[, 1]],
ID2 = .SD[[1]][w[, 2]])
l <- list(ID1 = .SD[[1]][w[, 1]],
ID2 = .SD[[1]][w[, 2]])
}
l
},
by = splitBy, .SDcols = c(id, coords)]

Expand Down
11 changes: 6 additions & 5 deletions R/edge_nn.R
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,14 @@ edge_nn <- function(DT = NULL,

if (returnDist) {
w <- wm + (length(wm) * (as.numeric(names(wm)) - 1))
list(ID = .SD[[1]][as.numeric(names(wm))],
NN = .SD[[1]][wm],
distance = distMatrix[w])
l <- list(ID = .SD[[1]][as.numeric(names(wm))],
NN = .SD[[1]][wm],
distance = distMatrix[w])
} else {
list(ID = .SD[[1]][as.numeric(names(wm))],
NN = .SD[[1]][wm])
l <- list(ID = .SD[[1]][as.numeric(names(wm))],
NN = .SD[[1]][wm])
}
l
},
by = splitBy, .SDcols = c(id, coords)]
}
Expand Down

0 comments on commit 75042b8

Please sign in to comment.