Skip to content

Commit

Permalink
trapset is.function better messages etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
MurrayEfford committed May 1, 2024
1 parent 14fed81 commit b33e2a7
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 9 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: secrdesign
Type: Package
Title: Sampling Design for Spatially Explicit Capture-Recapture
Version: 2.9.1
Date: 2024-04-20
Version: 2.9.2
Date: 2024-05-01
Description: Tools for designing spatially explicit capture-recapture studies of animal populations. This is primarily a simulation manager for package 'secr'. Extensions in version 2.5.0 include costing and evaluation of detector spacing.
Authors@R: c(person("Murray", "Efford",
email = "[email protected]",
Expand Down
3 changes: 2 additions & 1 deletion NEWS
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Changes in version 2.9.2 (2024-04-30)
Changes in version 2.9.2 (2024-05-01)

New features or changed behaviour of old functions
o none
Expand All @@ -9,6 +9,7 @@ Bugs fixed
Other
o internal function dfcast accepts character detectfn
o plot.optimalSpacing tweaked to allow pch other than 1 and new plottype option
o run.scenarios() with trapset functions outputs a message as each is tested

Changes in version 2.9.1 (2024-04-20)

Expand Down
12 changes: 9 additions & 3 deletions R/run.scenarios.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
## 2023-05-26 byscenario = TRUE fixed
## 2023-05-28 dynamic maskset for trapset function UNTESTED
## 2024-03-01 joinsessions argument
## 2024-05-01 is.function(trapset) messages
###############################################################################
wrapifneeded <- function (args, default) {
if (any(names(args) %in% names(default)))
Expand Down Expand Up @@ -255,7 +256,6 @@ makeCH <- function (scenario, trapset, full.pop.args, full.det.args,

#####################
## simulate detection

CHi <- do.call(CHfun, detarg)
if (joinsessions && ms(CHi)) CHi <- join(CHi) ## 2024-03-01

Expand Down Expand Up @@ -578,7 +578,6 @@ run.scenarios <- function (
# not forcing match.arg for CH.function allows user function
CH.function <- CH.function[1]
fit.function <- match.arg(fit.function)

starttime <- format(Sys.time(), "%H:%M:%S %d %b %Y")
ncores <- secr::setNumThreads(ncores) ## 2022-12-29
if (byscenario && (ncores > nrow(scenarios)))
Expand Down Expand Up @@ -609,16 +608,23 @@ run.scenarios <- function (
if (is.null(names(trapset)))
names(trapset) <- paste('traps',1:nk, sep='')

if (is.function(trapset[[1]])) {
if (any(sapply(trapset, is.function))) {
if (!all(sapply(trapset, is.function)))
stop ("all trapset must be a function if any is a function")
if (missing(maskset))
stop ("maskset should be provided if trapset is list of functions")
temptrapset <- list()
for (i in 1:length(trapset)) {
message ("Testing trapset function ", i, "...")
temptrapset[[i]] <- do.call(trapset[[i]], trap.args[[i]])
}
dettype <- sapply(temptrapset, detector)[scenarios$trapsindex]
sight <- sapply(temptrapset, function(x)
if(ms(x)) sighting(x[[1]]) else sighting(x))
message ("Testing complete")
message ("Detectors ", paste(
sapply(temptrapset, function(x) if(ms(x)) nrow(x[[1]]) else nrow(x)),
collapse = ', '))
}
else {
dettype <- sapply(trapset, detector)[scenarios$trapsindex]
Expand Down
2 changes: 1 addition & 1 deletion man/run.scenarios.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ A similar effect may be achieved by providing a custom extractfn and passing arg
From 2.2.0, two or more rows in \code{scenarios} may share the same scenario number. This is used to generate multiple population subclasses (e.g. sexes) differing in density and/or detection parameters. If \code{multisession = TRUE} the subclasses become separate sessions in a multi-session capthist object (this may require a custom \code{extractfn}). \code{multisession} is ignored with a warning if each scenario row has a unique number.
From 2.7.0, each component of `trapset' may be a function that constructs a detector layout. This allows layouts to be constructed dynamically at the time each capthist is generated; arguments of each function are provided in the `trap.args' list. The primary purpose is to allow systematic grids, laceworks etc. to be constructed with a unique random origin for each replicate. The `maskset' argument must be provided - it should cover all potential layouts, regardless of origins.
From 2.7.0, each component of `trapset' may be a function that constructs a detector layout. This allows layouts to be constructed dynamically at the time each capthist is generated; arguments of each function are provided in the `trap.args' list which should be of the same length as `trapset' The primary purpose is to allow systematic grids, laceworks etc. to be constructed with a unique random origin for each replicate. The `maskset' argument must be provided - it should cover all potential layouts, regardless of origins.

In \code{fit.models} the arguments \code{scen} and \code{repl} may be used to select a subset of datasets for model fitting.

Expand Down
4 changes: 2 additions & 2 deletions man/secrdesign-package.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ Tools to assist the design of spatially explicit capture--recapture studies of a
\tabular{ll}{
Package: \tab secr\cr
Type: \tab Package\cr
Version: \tab 2.9.1\cr
Date: \tab 2024-04-20\cr
Version: \tab 2.9.2\cr
Date: \tab 2024-05-01\cr
License: \tab GNU General Public License Version 2 or later\cr
}

Expand Down

0 comments on commit b33e2a7

Please sign in to comment.