Skip to content

Commit

Permalink
Merge pull request #165 from dsmith-unbc/issue-#142-Return-dist.mat-e…
Browse files Browse the repository at this point in the history
…ven-if-it-is-invalid

Issue #142 return dist.mat even if it is invalid
  • Loading branch information
hugomflavio authored Dec 12, 2024
2 parents 0986980 + fc635a1 commit 980edfe
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 46 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: actel
Title: Acoustic Telemetry Data Analysis
Version: 1.3.0.9017
Version: 1.3.0.9018
Authors@R: c(
person("Hugo", "Flávio", role = c("aut", "cre"),
email = "[email protected]", comment = c(ORCID = "0000-0002-5174-1197")),
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Enhancements:
* New `plotDot()` function to help users inspect their spatial.txt files (issue [#55](https://github.com/hugomflavio/actel/issues/55)).
* Improved internal mechanisms for message/warning/debug/stop reporting. new internal function `event()` replaces the old `appendTo()`, `stopAndReport()`, and `emergencyBreak()` (issue [#135](https://github.com/hugomflavio/actel/issues/135))
* Added the ability to use output of `loadSpatial()` as 'starters' for `distancesMatrix()` when 'actel' is 'TRUE'. This allows a user to input their spatial.csv if located in a separate working directory (issue [#133](https://github.com/hugomflavio/actel/issues/133))
* Distance matrix is now retained in the output of `explore()`, `residency()`, and `migration()` analysis when invalid. Additionally, if the distance matrix is not available NA will be denoted in the output. (issue [#142](https://github.com/hugomflavio/actel/issues/142))

## actel 1.3.0

Expand Down
15 changes: 5 additions & 10 deletions R/explore.R
Original file line number Diff line number Diff line change
Expand Up @@ -520,12 +520,9 @@ explore <- function(
if (decision == "y") { # nocov start
event(type = c("screen", "report"),
paste0("M: Saving results as '", resultsname, "'."))
if (attributes(dist.mat)$valid)
save(bio, detections, valid.detections, spatial, deployments, arrays,
movements, valid.movements, times, rsp.info, dist.mat, file = resultsname)
else
save(bio, detections, valid.detections, spatial, deployments, arrays,
movements, valid.movements, times, rsp.info, file = resultsname)
save(bio, detections, valid.detections, spatial, deployments, arrays,
movements, valid.movements, times, rsp.info, dist.mat,
file = resultsname)
} else {
event(type = c("screen", "report"),
paste0("M: Skipping saving of the results."))
Expand Down Expand Up @@ -688,10 +685,8 @@ explore <- function(
movements = movements,
valid.movements = valid.movements,
times = times,
rsp.info = rsp.info)

if (attributes(dist.mat)$valid)
output$dist.mat <- dist.mat
rsp.info = rsp.info,
dist.mat = dist.mat)

event(type = "Screen",
"M: Analysis completed!")
Expand Down
25 changes: 7 additions & 18 deletions R/migration.R
Original file line number Diff line number Diff line change
Expand Up @@ -831,19 +831,11 @@ migration <- function(
# in coding style (actel 2.0).
section.movements <- secmoves
intra.array.matrices <- intra_mats
if (attributes(dist.mat)$valid) {
save(detections, valid.detections, spatial, deployments, arrays,
movements, valid.movements, section.movements, status.df,
section.overview, group.overview, release.overview, matrices,
overall.CJS, intra.array.matrices, intra.array.CJS, times,
rsp.info, dist.mat, file = resultsname)
} else {
save(detections, valid.detections, spatial, deployments, arrays,
movements, valid.movements, section.movements, status.df,
section.overview, group.overview, release.overview, matrices,
overall.CJS, intra.array.matrices, intra.array.CJS, times,
rsp.info, file = resultsname)
}
save(detections, valid.detections, spatial, deployments, arrays,
movements, valid.movements, section.movements, status.df,
section.overview, group.overview, release.overview, matrices,
overall.CJS, intra.array.matrices, intra.array.CJS, times,
rsp.info, dist.mat, file = resultsname)
} else { # nocov end
event(type = c("screen", "report"),
"M: Skipping saving of the results.")
Expand Down Expand Up @@ -1065,11 +1057,8 @@ migration <- function(
intra.array.matrices = intra_mats,
intra.array.CJS = intra.array.CJS,
times = times,
rsp.info = rsp.info)

if (attributes(dist.mat)$valid) {
output$dist.mat <- dist.mat
}
rsp.info = rsp.info,
dist.mat = dist.mat)

event(type = "screen",
"M: Analysis completed!")
Expand Down
20 changes: 6 additions & 14 deletions R/residency.R
Original file line number Diff line number Diff line change
Expand Up @@ -660,16 +660,10 @@ residency <- function(
if (decision == "y") {
event(type = c("screen", "report"),
"M: Saving results as '", resultsname, "'.")
if (attributes(dist.mat)$valid)
save(detections, valid.detections, spatial, deployments, arrays, movements, valid.movements,
section.movements, status.df, last.seen, array.times, section.times, intra.array.matrices,
residency.list, time.ratios, time.positions, global.ratios, group.ratios, efficiency,
intra.array.CJS, rsp.info, dist.mat, file = resultsname)
else
save(detections, valid.detections, spatial, deployments, arrays, movements, valid.movements,
section.movements, status.df, last.seen, array.times, section.times, intra.array.matrices,
residency.list, time.ratios, time.positions, global.ratios, group.ratios, efficiency,
intra.array.CJS, rsp.info, file = resultsname)
save(detections, valid.detections, spatial, deployments, arrays, movements, valid.movements,
section.movements, status.df, last.seen, array.times, section.times, intra.array.matrices,
residency.list, time.ratios, time.positions, global.ratios, group.ratios, efficiency,
intra.array.CJS, rsp.info, dist.mat, file = resultsname)
} else {
event(type = c("screen", "report"),
"M: Skipping saving of the results.")
Expand Down Expand Up @@ -883,10 +877,8 @@ residency <- function(
global.ratios = global.ratios,
group.ratios = group.ratios,
last.seen = last.seen,
rsp.info = rsp.info)

if (attributes(dist.mat)$valid)
output$dist.mat <- dist.mat
rsp.info = rsp.info,
dist.mat = dist.mat)

event(type = "screen",
"M: Analysis completed!")
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test_explore.R
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ test_that("explore is able to run speed and inactiveness checks.", {
file.remove("distances.csv")
output <- suppressWarnings(explore(tz = 'Europe/Copenhagen', report = TRUE, GUI = "never", speed.warning = 1000000, inactive.warning = 1000000))
expect_false(any(is.na(match(names(output), c('bio', 'detections', 'valid.detections', 'spatial', 'deployments', 'arrays',
'movements', 'valid.movements', 'times', 'rsp.info')))))
'movements', 'valid.movements', 'times', 'rsp.info', 'dist.mat')))))
})
# n
# n
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test_migration.R
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ test_that("migration is able to run speed and inactiveness checks.", {
GUI = "never", speed.error = 1000000, inactive.error = 1000000),
"Running inactiveness checks without a distance matrix. Performance may be limited.", fixed = TRUE)

expect_false(any(is.na(match(names(output), c('arrays', 'deployments', 'detections', 'group.overview', 'intra.array.CJS',
expect_false(any(is.na(match(names(output), c('arrays', 'deployments', 'detections', 'dist.mat', 'group.overview', 'intra.array.CJS',
'intra.array.matrices','matrices', 'movements', 'overall.CJS', 'release.overview', 'rsp.info', 'section.movements',
'section.overview', 'spatial', 'status.df', 'times', 'valid.detections', 'valid.movements')))))
})
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test_residency.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ test_that("residency is able to run speed and inactiveness checks.", {
GUI = "never", speed.error = 1000000, inactive.error = 1000000),
"Running inactiveness checks without a distance matrix. Performance may be limited.", fixed = TRUE)
expect_false(any(is.na(match(names(output), c('array.times', 'arrays', 'time.positions', 'time.ratios',
'deployments', 'detections', 'efficiency', 'global.ratios', 'group.ratios', 'intra.array.CJS', 'intra.array.matrices',
'deployments', 'detections', 'dist.mat', 'efficiency', 'global.ratios', 'group.ratios', 'intra.array.CJS', 'intra.array.matrices',
'last.seen', 'movements', 'residency.list', 'rsp.info', 'section.movements', 'section.times',
'spatial', 'status.df', 'valid.detections', 'valid.movements')))))
})
Expand Down

0 comments on commit 980edfe

Please sign in to comment.