Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix edge_dist and edge_nn names warnings+error #25

Merged
merged 4 commits into from
Mar 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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