Skip to content

Commit

Permalink
Suggested fix for #157
Browse files Browse the repository at this point in the history
Initial steps to building testing. I do not know what effects there might be of changing the labelling of transects at this stage. Possibly nothing as replicated are renamed any way.
  • Loading branch information
LHMarshall committed Dec 20, 2023
1 parent ce0c77d commit 4c5e820
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
10 changes: 10 additions & 0 deletions R/bootdht_resample_data.R
Expand Up @@ -18,6 +18,16 @@ bootdht_resample_data <- function(bootdat, our_resamples,

# get all samples per stratum
samps_per_strata <- unique(bf[, c(stratum_label, sample_label)])
# Check that the sampler names are unique across strata
# The number of unique sampler names should be the same as the rows in samps_per_strata
if(!nrow(samps_per_strata) == length(unique(samps_per_strata[[sample_label]]))){
# Copy old sample IDs
bootdat$old.Sample.Label <- bootdat[[sample_label]]
# Update to unique sample labels by combining stratum label and sample label
bootdat[[sample_label]] <- paste(bootdat[[stratum_label]], bootdat[[sample_label]], sep = ".")
samps_per_strata[[sample_label]] <- paste(samps_per_strata[[stratum_label]], samps_per_strata[[sample_label]], sep = ".")
bf[[sample_label]] <- paste(bf[[stratum_label]], bf[[sample_label]], sep = ".")
}
samps_per_strata <- by(bf[,c(stratum_label, sample_label)],
bf[[stratum_label]],
function(x) unique(x[[sample_label]]))
Expand Down
22 changes: 21 additions & 1 deletion tests/testthat/test_bootdht.R
Expand Up @@ -171,4 +171,24 @@ test_that("Issue #158 is fixed (stratum names > 'Total' bug)", {
set.seed(225)
bootout <- bootdht(mod1, flatfile=minke, nboot=3)
expect_true(nrow(bootout) > 0)
})
})



# generate some data to test on
dat <- data.frame(object = 1:60, Sample.Label = rep(1:10,6),
Area = 100, Effort = 1000)
dat$Region.Label <- c(rep("StrataA", 30), rep("StrataB", 30))
dat$distance <- abs(rnorm(nrow(dat), 0, 25))
dat$size <- rpois(nrow(dat), 20)
dat$ref.object <- dat$object

test_that("Issue #157 is fixed", {

set.seed(123)
obs <- bootdht_resample_data(dat, c("Sample.Label"))

#unique(obs[,c("Region.Label","Sample.Label")])
# test that there are 10 samplers in each strata
# check that the correct original object ID's are associated with each sampler
})

0 comments on commit 4c5e820

Please sign in to comment.