From 173012c262e57fd8186d60d1ec794080453f2979 Mon Sep 17 00:00:00 2001 From: ericarcher Date: Sun, 8 Jun 2025 11:02:10 -0700 Subject: [PATCH 1/2] v 0.9.7 move to SWFSC/banter and resubmission to CRAN --- .Rbuildignore | 0 .github/.gitignore | 0 .github/workflows/R-CMD-check.yaml | 0 .gitignore | 0 DESCRIPTION | 11 +++--- NAMESPACE | 1 - R/addBanterDetector.R | 26 +++++++-------- R/banter-package.R | 5 ++- R/banterGuide.R | 0 R/banter_detector.R | 0 R/banter_model.R | 0 R/getBanterModel.R | 2 +- R/getBanterModelData.R | 0 R/getDetectorNames.R | 0 R/getSampSize.R | 0 R/initBanterModel.R | 0 R/internals.R | 14 ++++---- R/modelPctCorrect.R | 12 +++---- R/numCalls.R | 32 +++++++++--------- R/numEvents.R | 9 +++-- R/plotDetectorTrace.R | 0 R/predict.R | 52 ++++++++++++++--------------- R/runBanterModel.R | 34 +++++++++---------- R/subsampleDetections.R | 0 R/summary.R | 0 README.md | 14 +++++--- _devel/Banter Guidelines Edits.pdf | Bin _devel/CalCurCEAS analysis.R | 4 +-- _devel/CalCurCEAS plots.pdf | Bin _devel/banterGuide.Rmd | 6 ++-- _devel/banterGuide.html | 0 _devel/banterGuide_old.Rmd | 4 +-- _devel/package test.R | 4 +-- _devel/pws.example.4.anne.R | 26 +++++++-------- banter.Rproj | 1 + data/test.data.rdata | Bin data/train.data.rdata | Bin inst/CITATION | 0 man/addBanterDetector.Rd | 0 man/banter-package.Rd | 1 - man/banterGuide.Rd | 0 man/banter_detector-class.Rd | 0 man/banter_model-class.Rd | 0 man/getBanterModel.Rd | 2 +- man/getBanterModelData.Rd | 0 man/getDetectorNames.Rd | 0 man/getSampSize.Rd | 0 man/initBanterModel.Rd | 0 man/internals.Rd | 0 man/modelPctCorrect.Rd | 0 man/numCalls.Rd | 0 man/numEvents.Rd | 0 man/plotDetectorTrace.Rd | 0 man/predict.Rd | 0 man/runBanterModel.Rd | 0 man/subsampleDetections.Rd | 0 man/summary.Rd | 0 man/test.data.Rd | 0 man/train.data.Rd | 0 tests/testthat.R | 0 tests/testthat/test-accessors.R | 2 +- tests/testthat/test-init.R | 0 tests/testthat/test-numCalls | Bin tests/testthat/test-summary | Bin 64 files changed, 131 insertions(+), 131 deletions(-) mode change 100644 => 100755 .Rbuildignore mode change 100644 => 100755 .github/.gitignore mode change 100644 => 100755 .github/workflows/R-CMD-check.yaml mode change 100644 => 100755 .gitignore mode change 100644 => 100755 DESCRIPTION mode change 100644 => 100755 NAMESPACE mode change 100644 => 100755 R/addBanterDetector.R mode change 100644 => 100755 R/banter-package.R mode change 100644 => 100755 R/banterGuide.R mode change 100644 => 100755 R/banter_detector.R mode change 100644 => 100755 R/banter_model.R mode change 100644 => 100755 R/getBanterModel.R mode change 100644 => 100755 R/getBanterModelData.R mode change 100644 => 100755 R/getDetectorNames.R mode change 100644 => 100755 R/getSampSize.R mode change 100644 => 100755 R/initBanterModel.R mode change 100644 => 100755 R/internals.R mode change 100644 => 100755 R/modelPctCorrect.R mode change 100644 => 100755 R/numCalls.R mode change 100644 => 100755 R/numEvents.R mode change 100644 => 100755 R/plotDetectorTrace.R mode change 100644 => 100755 R/predict.R mode change 100644 => 100755 R/runBanterModel.R mode change 100644 => 100755 R/subsampleDetections.R mode change 100644 => 100755 R/summary.R mode change 100644 => 100755 README.md mode change 100644 => 100755 _devel/Banter Guidelines Edits.pdf mode change 100644 => 100755 _devel/CalCurCEAS analysis.R mode change 100644 => 100755 _devel/CalCurCEAS plots.pdf mode change 100644 => 100755 _devel/banterGuide.Rmd mode change 100644 => 100755 _devel/banterGuide.html mode change 100644 => 100755 _devel/banterGuide_old.Rmd mode change 100644 => 100755 _devel/package test.R mode change 100644 => 100755 _devel/pws.example.4.anne.R mode change 100644 => 100755 banter.Rproj mode change 100644 => 100755 data/test.data.rdata mode change 100644 => 100755 data/train.data.rdata mode change 100644 => 100755 inst/CITATION mode change 100644 => 100755 man/addBanterDetector.Rd mode change 100644 => 100755 man/banter-package.Rd mode change 100644 => 100755 man/banterGuide.Rd mode change 100644 => 100755 man/banter_detector-class.Rd mode change 100644 => 100755 man/banter_model-class.Rd mode change 100644 => 100755 man/getBanterModel.Rd mode change 100644 => 100755 man/getBanterModelData.Rd mode change 100644 => 100755 man/getDetectorNames.Rd mode change 100644 => 100755 man/getSampSize.Rd mode change 100644 => 100755 man/initBanterModel.Rd mode change 100644 => 100755 man/internals.Rd mode change 100644 => 100755 man/modelPctCorrect.Rd mode change 100644 => 100755 man/numCalls.Rd mode change 100644 => 100755 man/numEvents.Rd mode change 100644 => 100755 man/plotDetectorTrace.Rd mode change 100644 => 100755 man/predict.Rd mode change 100644 => 100755 man/runBanterModel.Rd mode change 100644 => 100755 man/subsampleDetections.Rd mode change 100644 => 100755 man/summary.Rd mode change 100644 => 100755 man/test.data.Rd mode change 100644 => 100755 man/train.data.Rd mode change 100644 => 100755 tests/testthat.R mode change 100644 => 100755 tests/testthat/test-accessors.R mode change 100644 => 100755 tests/testthat/test-init.R mode change 100644 => 100755 tests/testthat/test-numCalls mode change 100644 => 100755 tests/testthat/test-summary diff --git a/.Rbuildignore b/.Rbuildignore old mode 100644 new mode 100755 diff --git a/.github/.gitignore b/.github/.gitignore old mode 100644 new mode 100755 diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml old mode 100644 new mode 100755 diff --git a/.gitignore b/.gitignore old mode 100644 new mode 100755 diff --git a/DESCRIPTION b/DESCRIPTION old mode 100644 new mode 100755 index a909fb1..c48ff7a --- a/DESCRIPTION +++ b/DESCRIPTION @@ -4,13 +4,12 @@ Title: BioAcoustic eveNT classifiER Description: Create a hierarchical acoustic event species classifier out of multiple call type detectors as described in Rankin et al (2017) . -Version: 0.9.6 +Version: 0.9.7 Authors@R: c( - EA = person("Eric", "Archer", email = "eric.archer@noaa.gov", role = c("aut", "cre")), - TS = person("Taiki", "Sakai", email = "taiki.sakai@noaa.gov", role = c("aut"))) + EA = person("Eric", "Archer", email = "eric.ivan.archer@gmail.com", role = c("aut", "cre")), + SR = person("Shannon", "Rankin", email = "shannon.rankin@noaa.gov", role = c("aut"))) Depends: - R (>= 4.1.0), - magrittr + R (>= 4.1.0) Imports: dplyr (>= 1.0.6), ggplot2 (>= 3.3.3), @@ -26,5 +25,5 @@ Imports: tidyr (>= 1.1.1) Suggests: testthat License: GNU General Public License -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.2 Encoding: UTF-8 diff --git a/NAMESPACE b/NAMESPACE old mode 100644 new mode 100755 index 670478a..b24aeb6 --- a/NAMESPACE +++ b/NAMESPACE @@ -19,6 +19,5 @@ export(runBanterModel) export(subsampleDetections) exportMethods(predict) exportMethods(summary) -importFrom(magrittr,"%>%") importFrom(methods,new) importFrom(rlang,.data) diff --git a/R/addBanterDetector.R b/R/addBanterDetector.R old mode 100644 new mode 100755 index 8521f72..6c43dc4 --- a/R/addBanterDetector.R +++ b/R/addBanterDetector.R @@ -116,11 +116,11 @@ removeBanterDetector <- function(x, name) { start <- Sys.time() # Combine event data with call ids in detector - df <- x@data %>% - dplyr::select(.data$event.id, .data$species) %>% - dplyr::inner_join(data, by = "event.id") %>% - dplyr::mutate(species = as.character(.data$species)) %>% - as.data.frame + df <- x@data |> + dplyr::select(.data$event.id, .data$species) |> + dplyr::inner_join(data, by = "event.id") |> + dplyr::mutate(species = as.character(.data$species)) |> + as.data.frame() # Check if any columns need to be removed because of missing data to.remove <- sapply(df, function(i) any(is.na(i))) @@ -143,12 +143,12 @@ removeBanterDetector <- function(x, name) { if(is.null(sampsize)) return(NULL) # Remove missing species and format columns - df <- df %>% - dplyr::filter(.data$species %in% names(sampsize)) %>% - dplyr::mutate(species = factor(.data$species)) %>% - dplyr::mutate(id = paste0(.data$event.id, ".", .data$call.id)) %>% - tibble::column_to_rownames("id") %>% - as.data.frame() %>% + df <- df |> + dplyr::filter(.data$species %in% names(sampsize)) |> + dplyr::mutate(species = factor(.data$species)) |> + dplyr::mutate(id = paste0(.data$event.id, ".", .data$call.id)) |> + tibble::column_to_rownames("id") |> + as.data.frame() |> droplevels() # Setup number of cores @@ -157,7 +157,7 @@ removeBanterDetector <- function(x, name) { # Create random forest parameter list params <- list( - predictors = df %>% + predictors = df |> dplyr::select(-.data$event.id, -.data$call.id, -.data$species), response = df$species, sampsize = sampsize, @@ -206,4 +206,4 @@ removeBanterDetector <- function(x, name) { proximity = FALSE, norm.votes = FALSE ) -} \ No newline at end of file +} diff --git a/R/banter-package.R b/R/banter-package.R old mode 100644 new mode 100755 index 3baffdb..c5a5837 --- a/R/banter-package.R +++ b/R/banter-package.R @@ -1,6 +1,5 @@ #' banter #' -#' @docType package #' @name banter-package #' @aliases banter #' @title BioAcoustic EveNT ClassifiER @@ -9,10 +8,10 @@ #' of dolphins in the California Current using whistles, echolocation clicks, #' and burst pulses. Marine Mammal Science 33:520-540. doi:10.1111/mms.12381 #' @importFrom rlang .data -#' @importFrom magrittr %>% #' @importFrom methods new #' @keywords package NULL +"_PACKAGE" .onAttach <- function(libname, pkgname) { packageStartupMessage( @@ -46,4 +45,4 @@ NULL #' @usage data(test.data) #' @format list #' @keywords datasets -NULL \ No newline at end of file +NULL diff --git a/R/banterGuide.R b/R/banterGuide.R old mode 100644 new mode 100755 diff --git a/R/banter_detector.R b/R/banter_detector.R old mode 100644 new mode 100755 diff --git a/R/banter_model.R b/R/banter_model.R old mode 100644 new mode 100755 diff --git a/R/getBanterModel.R b/R/getBanterModel.R old mode 100644 new mode 100755 index 447ea73..9cfc257 --- a/R/getBanterModel.R +++ b/R/getBanterModel.R @@ -5,7 +5,7 @@ #' @param model name of model to extract. Default is \code{"event"} #' to extract the event-level model. Can also be the name of a detector. #' -#' @return a \code{\link{randomForest}} model object. +#' @return a \code{\link[randomForest]{randomForest}} model object. #' #' @author Eric Archer \email{eric.archer@@noaa.gov} #' diff --git a/R/getBanterModelData.R b/R/getBanterModelData.R old mode 100644 new mode 100755 diff --git a/R/getDetectorNames.R b/R/getDetectorNames.R old mode 100644 new mode 100755 diff --git a/R/getSampSize.R b/R/getSampSize.R old mode 100644 new mode 100755 diff --git a/R/initBanterModel.R b/R/initBanterModel.R old mode 100644 new mode 100755 diff --git a/R/internals.R b/R/internals.R old mode 100644 new mode 100755 index 0797fd0..f19b914 --- a/R/internals.R +++ b/R/internals.R @@ -95,18 +95,18 @@ #' .meanVotes <- function(x) { df <- sapply(names(x), function(d) { - x[[d]] %>% + x[[d]] |> tidyr::pivot_longer( -.data$event.id, names_to = "species", values_to = "prob" - ) %>% - dplyr::mutate(species = paste0(d, ".", .data$species)) %>% - dplyr::group_by(.data$event.id, .data$species) %>% + ) |> + dplyr::mutate(species = paste0(d, ".", .data$species)) |> + dplyr::group_by(.data$event.id, .data$species) |> dplyr::summarize(prob.mean = mean(.data$prob), .groups = "drop") - }, simplify = FALSE) %>% - dplyr::bind_rows() %>% + }, simplify = FALSE) |> + dplyr::bind_rows() |> tidyr::pivot_wider(names_from = "species", values_from = "prob.mean") replace(df, is.na(df), 0) -} \ No newline at end of file +} diff --git a/R/modelPctCorrect.R b/R/modelPctCorrect.R old mode 100644 new mode 100755 index 791d5f0..3c98381 --- a/R/modelPctCorrect.R +++ b/R/modelPctCorrect.R @@ -49,12 +49,12 @@ modelPctCorrect <- function(x) { model = model, stringsAsFactors = FALSE ) - }) %>% - dplyr::bind_rows() %>% + }) |> + dplyr::bind_rows() |> dplyr::mutate( model = factor(.data$model, levels = c(names(x@detectors), "event")) - ) %>% - tidyr::pivot_wider(names_from = "model", values_from = "pct.correct") %>% - dplyr::mutate(species = factor(.data$species, levels = c(spp, "Overall"))) %>% + ) |> + tidyr::pivot_wider(names_from = "model", values_from = "pct.correct") |> + dplyr::mutate(species = factor(.data$species, levels = c(spp, "Overall"))) |> dplyr::arrange(.data$species) -} \ No newline at end of file +} diff --git a/R/numCalls.R b/R/numCalls.R old mode 100644 new mode 100755 index c97a8ae..8aada29 --- a/R/numCalls.R +++ b/R/numCalls.R @@ -39,16 +39,16 @@ numCalls <- function(x, by = c("species", "event")) { if(is.null(x@detectors)) stop("no detectors loaded in model.") by <- switch(match.arg(by), species = "species", event = "event.id") df <- lapply(names(x@detectors), function(d) { - x@data %>% - dplyr::left_join(x@detectors[[d]]@ids, by = "event.id") %>% - dplyr::group_by(dplyr::across(by)) %>% - dplyr::summarize(n = sum(!is.na(.data$call.id)), .groups = "drop") %>% + x@data |> + dplyr::left_join(x@detectors[[d]]@ids, by = "event.id") |> + dplyr::group_by(dplyr::across(by)) |> + dplyr::summarize(n = sum(!is.na(.data$call.id)), .groups = "drop") |> dplyr::mutate(detector = paste0("num.", d)) - }) %>% - dplyr::bind_rows() %>% + }) |> + dplyr::bind_rows() |> tidyr::pivot_wider(names_from = "detector", values_from = "n") - replace(df, is.na(df), 0) %>% + replace(df, is.na(df), 0) |> as.data.frame() } @@ -58,17 +58,17 @@ numCalls <- function(x, by = c("species", "event")) { propCalls <- function(x, by = c("species", "event")) { df <- numCalls(x, by) by <- colnames(df)[1] - df %>% + df |> tidyr::pivot_longer( -dplyr::all_of(by), names_to = "detector", values_to = "n" - ) %>% - dplyr::group_by(dplyr::across(by)) %>% - dplyr::mutate(prop = .data$n / sum(.data$n, na.rm = TRUE)) %>% - dplyr::ungroup() %>% - dplyr::select(-.data$n) %>% - dplyr::mutate(detector = gsub("num.", "prop.", .data$detector)) %>% - tidyr::pivot_wider(names_from = "detector", values_from = "prop") %>% + ) |> + dplyr::group_by(dplyr::across(by)) |> + dplyr::mutate(prop = .data$n / sum(.data$n, na.rm = TRUE)) |> + dplyr::ungroup() |> + dplyr::select(-.data$n) |> + dplyr::mutate(detector = gsub("num.", "prop.", .data$detector)) |> + tidyr::pivot_wider(names_from = "detector", values_from = "prop") |> as.data.frame() -} \ No newline at end of file +} diff --git a/R/numEvents.R b/R/numEvents.R old mode 100644 new mode 100755 index 7e45ec6..090ce69 --- a/R/numEvents.R +++ b/R/numEvents.R @@ -32,7 +32,6 @@ #' # number of events in burst pulse (bp) detector model #' numEvents(bant.mdl, "bp") #' -#' @importFrom magrittr %>% #' @importFrom rlang .data #' #' @export @@ -42,12 +41,12 @@ numEvents <- function(x, model = "event") { df <- if(model == "event") { x@data } else { - x@data %>% + x@data |> dplyr::filter(.data$event.id %in% x@detectors[[model]]@ids$event.id) } spp.fac <- factor(df$species, levels = sort(unique(x@data$species))) - table(species = spp.fac) %>% - as.data.frame() %>% - stats::setNames(c("species", "num.events")) %>% + table(species = spp.fac) |> + as.data.frame() |> + stats::setNames(c("species", "num.events")) |> dplyr::mutate(species = as.character(.data$species)) } diff --git a/R/plotDetectorTrace.R b/R/plotDetectorTrace.R old mode 100644 new mode 100755 diff --git a/R/predict.R b/R/predict.R old mode 100644 new mode 100755 index 9d31273..0439c31 --- a/R/predict.R +++ b/R/predict.R @@ -123,10 +123,10 @@ predict.banter_model <- function(object, new.data, ...) { # Get number of calls in each detector for each event detector.num <- lapply(names(object@detectors), function(d) { if(d %in% names(new.data$detectors)) { - new.data$events %>% - dplyr::left_join(new.data$detectors[[d]], by = "event.id") %>% - dplyr::group_by(.data$event.id) %>% - dplyr::summarize(n = sum(!is.na(.data$call.id)), .groups = "drop") %>% + new.data$events |> + dplyr::left_join(new.data$detectors[[d]], by = "event.id") |> + dplyr::group_by(.data$event.id) |> + dplyr::summarize(n = sum(!is.na(.data$call.id)), .groups = "drop") |> dplyr::mutate(detector = paste0("prop.", d)) } else { # detector not present in new.data, proportion = 0 tibble::tibble( @@ -135,16 +135,16 @@ predict.banter_model <- function(object, new.data, ...) { detector = paste0("prop.", d) ) } - }) %>% + }) |> dplyr::bind_rows() # Convert number to proportion of calls - detector.prop <- detector.num %>% - dplyr::group_by(.data$event.id) %>% - dplyr::mutate(n = .data$n / sum(.data$n, na.rm = TRUE)) %>% - dplyr::ungroup() %>% + detector.prop <- detector.num |> + dplyr::group_by(.data$event.id) |> + dplyr::mutate(n = .data$n / sum(.data$n, na.rm = TRUE)) |> + dplyr::ungroup() |> tidyr::pivot_wider(names_from = "detector", values_from = "n") - detector.prop <- replace(detector.prop, is.na(detector.prop), 0) %>% + detector.prop <- replace(detector.prop, is.na(detector.prop), 0) |> as.data.frame() # Calculate mean votes for each event @@ -154,8 +154,8 @@ predict.banter_model <- function(object, new.data, ...) { object@detectors[[d]]@model, new.data$detectors[[d]], type = "prob" - ) %>% - as.data.frame() %>% + ) |> + as.data.frame() |> dplyr::bind_cols(event.id = new.data$detectors[[d]]$event.id) } else { # detector not present in model - fill with 0's spp <- colnames(object@detectors[[d]]@model$votes) @@ -163,29 +163,29 @@ predict.banter_model <- function(object, new.data, ...) { colnames(vote.0) <- spp dplyr::bind_cols(as.data.frame(vote.0), event.id = unique.events) } - }, simplify = FALSE) %>% + }, simplify = FALSE) |> .meanVotes() # Construct data.frame to predict - df <- new.data$events %>% - dplyr::left_join(detector.prop, by = "event.id") %>% + df <- new.data$events |> + dplyr::left_join(detector.prop, by = "event.id") |> dplyr::left_join(detector.votes, by = "event.id") # add call rate columns if duration is present and there is no missing data if("duration" %in% colnames(df)) { if(all(!is.na(df$duration))) { - df <- df %>% + df <- df |> dplyr::left_join( - detector.num %>% + detector.num |> dplyr::left_join( dplyr::select(df, "event.id", "duration"), by = "event.id" - ) %>% + ) |> dplyr::mutate( detector = gsub("prop.", "rate.", .data$detector), n = .data$n / .data$duration - ) %>% - dplyr::select(-.data$duration) %>% + ) |> + dplyr::select(-.data$duration) |> tidyr::pivot_wider(names_from = "detector", values_from = "n"), by = "event.id" ) @@ -206,11 +206,11 @@ predict.banter_model <- function(object, new.data, ...) { predict(object@model, df, type = "prob"), stringsAsFactors = FALSE ), - detector.freq = detector.num %>% - dplyr::mutate(detector = gsub("prop.", "", .data$detector)) %>% - dplyr::group_by(.data$detector) %>% - dplyr::summarize(num.events = sum(.data$n > 0)) %>% - dplyr::ungroup() %>% + detector.freq = detector.num |> + dplyr::mutate(detector = gsub("prop.", "", .data$detector)) |> + dplyr::group_by(.data$detector) |> + dplyr::summarize(num.events = sum(.data$n > 0)) |> + dplyr::ungroup() |> as.data.frame(stringsAsFactors = FALSE) ) @@ -237,4 +237,4 @@ predict.banter_model <- function(object, new.data, ...) { #' @name predict #' @rdname predict #' @aliases predict,banter_model-method -methods::setMethod("predict", "banter_model", predict.banter_model) \ No newline at end of file +methods::setMethod("predict", "banter_model", predict.banter_model) diff --git a/R/runBanterModel.R b/R/runBanterModel.R old mode 100644 new mode 100755 index f26041b..4bee48c --- a/R/runBanterModel.R +++ b/R/runBanterModel.R @@ -44,7 +44,7 @@ runBanterModel <- function(x, ntree, sampsize = 1) { as.data.frame(d@model$votes / rowSums(d@model$votes)), stringsAsFactors = FALSE ) - }, simplify = FALSE) %>% + }, simplify = FALSE) |> .meanVotes() # Check if any columns need to be removed because of missing data @@ -60,38 +60,38 @@ runBanterModel <- function(x, ntree, sampsize = 1) { } # construct full data to predict - df <- df %>% - dplyr::left_join(detector.prop, by = "event.id") %>% + df <- df |> + dplyr::left_join(detector.prop, by = "event.id") |> dplyr::left_join(detector.votes, by = "event.id") # add call rate columns if duration exists and there is no missing data if("duration" %in% colnames(df)) { if(all(!is.na(df$duration))) { - df <- df %>% + df <- df |> dplyr::left_join( - numCalls(x, "event") %>% + numCalls(x, "event") |> tidyr::pivot_longer( -.data$event.id, names_to = "detector", values_to = "num" - ) %>% + ) |> dplyr::left_join( dplyr::select(df, "event.id", "duration"), by = "event.id" - ) %>% + ) |> dplyr::mutate( detector = gsub("num.", "rate.", .data$detector), num = .data$num / .data$duration - ) %>% - dplyr::select(-.data$duration) %>% + ) |> + dplyr::select(-.data$duration) |> tidyr::pivot_wider(names_from = "detector", values_from = "num"), by = "event.id" ) } } - df <- df %>% - stats::na.omit() %>% + df <- df |> + stats::na.omit() |> dplyr::mutate(species = as.character(.data$species)) # Get and check requested sample size @@ -99,11 +99,11 @@ runBanterModel <- function(x, ntree, sampsize = 1) { if(is.null(sampsize)) return(x) # Remove species with insufficient sample sizes and finish data format - x@model.data <- df %>% - dplyr::filter(.data$species %in% names(sampsize)) %>% - dplyr::mutate(species = factor(.data$species)) %>% - tibble::column_to_rownames("event.id") %>% - as.data.frame() %>% + x@model.data <- df |> + dplyr::filter(.data$species %in% names(sampsize)) |> + dplyr::mutate(species = factor(.data$species)) |> + tibble::column_to_rownames("event.id") |> + as.data.frame() |> droplevels() x@model <- randomForest::randomForest( @@ -120,4 +120,4 @@ runBanterModel <- function(x, ntree, sampsize = 1) { x@timestamp["stop"] <- Sys.time() x -} \ No newline at end of file +} diff --git a/R/subsampleDetections.R b/R/subsampleDetections.R old mode 100644 new mode 100755 diff --git a/R/summary.R b/R/summary.R old mode 100644 new mode 100755 diff --git a/README.md b/README.md old mode 100644 new mode 100755 index b7b023b..3e5a9e8 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ To install the latest version from GitHub: if(!require('devtools')) install.packages('devtools') # install package from GitHub -devtools::install_github('ericarcher/banter') +devtools::install_github('SWFSC/banter') ``` ### For a complete tutorial, run `banterGuide()`. @@ -91,14 +91,18 @@ predict(bant.mdl, test.data) ### Contact -* submit suggestions and bug-reports: -* send a pull request: -* e-mail: +* submit suggestions and bug-reports: +* send a pull request: +* e-mail: ### Reference Rankin, S., Archer, F., Keating, J. L., Oswald, J. N., Oswald, M., Curtis, A. and Barlow, J. (2017) Acoustic classification of dolphins in the California Current using whistles, echolocation clicks, and burst pulses. Mar Mam Sci, 33: 520-540. [doi:10.1111/mms.12381](https://onlinelibrary.wiley.com/doi/abs/10.1111/mms.12381) -### version 0.9.6 (on CRAN) +### version 0.9.7 (on CRAN) + +* move package to SWFSC GitHub site + +### version 0.9.6 * changed behavior of `addBanterDetector()` to provide a warning instead of an error if a detector didn't have enough detections of a species and add all detectors that were valid. * minor bug fixes and edits for CRAN diff --git a/_devel/Banter Guidelines Edits.pdf b/_devel/Banter Guidelines Edits.pdf old mode 100644 new mode 100755 diff --git a/_devel/CalCurCEAS analysis.R b/_devel/CalCurCEAS analysis.R old mode 100644 new mode 100755 index 35bac21..b7e34c7 --- a/_devel/CalCurCEAS analysis.R +++ b/_devel/CalCurCEAS analysis.R @@ -6,8 +6,8 @@ library(gridExtra) load("data/calcurceas data.rdata") -ccc.mdl <- initBanterModel(survey.train$events) %>% - addBanterDetector(survey.train$detectors, ntree = 10000, sampsize = 100) %>% +ccc.mdl <- initBanterModel(survey.train$events) |> + addBanterDetector(survey.train$detectors, ntree = 10000, sampsize = 100) |> runBanterModel(ntree = 10000, sampsize = 3) pdf("CalCurCEAS plots.pdf") diff --git a/_devel/CalCurCEAS plots.pdf b/_devel/CalCurCEAS plots.pdf old mode 100644 new mode 100755 diff --git a/_devel/banterGuide.Rmd b/_devel/banterGuide.Rmd old mode 100644 new mode 100755 index a70c1bf..ee3c4ef --- a/_devel/banterGuide.Rmd +++ b/_devel/banterGuide.Rmd @@ -314,8 +314,8 @@ head(casePredict) This function returns a data frame with the original and predicted species for each event along with if the event was correctly classified and the assignment probabilities to each species. To identify misclassified events, we just filter this data frame and grab the original event id. ```{r, include=TRUE} -misclass <- casePredict %>% - filter(!is.correct) %>% +misclass <- casePredict |> + filter(!is.correct) |> select(id) ``` @@ -367,4 +367,4 @@ Many thanks to our original co-authors for their help in developing the original ## References Liaw, A. and M. Wiener. (2002) Classification and regression by randomForest. R News 2(3):18-22. -Rankin, S., Archer, F., Keating, J. L., Oswald, J. N., Oswald, M., Curtis, A. and Barlow, J. (2017) Acoustic classification of dolphins in the California Current using whistles, echolocation clicks, and burst pulses. Mar Mam Sci, 33: 520-540. \ No newline at end of file +Rankin, S., Archer, F., Keating, J. L., Oswald, J. N., Oswald, M., Curtis, A. and Barlow, J. (2017) Acoustic classification of dolphins in the California Current using whistles, echolocation clicks, and burst pulses. Mar Mam Sci, 33: 520-540. diff --git a/_devel/banterGuide.html b/_devel/banterGuide.html old mode 100644 new mode 100755 diff --git a/_devel/banterGuide_old.Rmd b/_devel/banterGuide_old.Rmd old mode 100644 new mode 100755 index 680efd2..253b9db --- a/_devel/banterGuide_old.Rmd +++ b/_devel/banterGuide_old.Rmd @@ -319,8 +319,8 @@ You can also save a separate data.frame for your training data that includes the ```{r, include=TRUE} casePredict <- casePredictions(bant.rf) -misclass <- casePredict %>% - filter(!is.correct) %>% +misclass <- casePredict |> + filter(!is.correct) |> select(id) ``` diff --git a/_devel/package test.R b/_devel/package test.R old mode 100644 new mode 100755 index eb24e10..6d31a90 --- a/_devel/package test.R +++ b/_devel/package test.R @@ -6,8 +6,8 @@ library(rfPermute) ## test package example data data(train.data) -ex.mdl <- initBanterModel(train.data$events) %>% - addBanterDetector(train.data$detectors, ntree = 100, sampsize = 1) %>% +ex.mdl <- initBanterModel(train.data$events) |> + addBanterDetector(train.data$detectors, ntree = 100, sampsize = 1) |> runBanterModel(ntree = 100, sampsize = 1) summary(ex.mdl) diff --git a/_devel/pws.example.4.anne.R b/_devel/pws.example.4.anne.R old mode 100644 new mode 100755 index e654e29..d31ea4a --- a/_devel/pws.example.4.anne.R +++ b/_devel/pws.example.4.anne.R @@ -4,33 +4,33 @@ library(banter) data(train.data) # add unique id for each bp detected -bp <- train.data$detectors$bp %>% +bp <- train.data$detectors$bp |> mutate(bp.id = as.character(1:n())) # pairwise distance of all bp detections -bp.dist <- bp %>% - select(-event.id, -call.id) %>% - column_to_rownames("bp.id") %>% - dist() %>% +bp.dist <- bp |> + select(-event.id, -call.id) |> + column_to_rownames("bp.id") |> + dist() |> as.matrix() # unique events events <- unique(bp$event.id) # data frame of unique pairs of events -event.pairs <- events %>% - combn(2) %>% - t() %>% - as.data.frame() %>% +event.pairs <- events |> + combn(2) |> + t() |> + as.data.frame() |> setNames(c("event.1", "event.2")) # add column for mean distance between pairs of events event.pairs$dist <- apply(event.pairs, 1, function(x) { - id.1 <- bp %>% - filter(event.id == x[1]) %>% + id.1 <- bp |> + filter(event.id == x[1]) |> pull(bp.id) - id.2 <- bp %>% - filter(event.id == x[2]) %>% + id.2 <- bp |> + filter(event.id == x[2]) |> pull(bp.id) mean(bp.dist[id.1, id.2]) }) diff --git a/banter.Rproj b/banter.Rproj old mode 100644 new mode 100755 index 1788e68..24aaf80 --- a/banter.Rproj +++ b/banter.Rproj @@ -1,4 +1,5 @@ Version: 1.0 +ProjectId: 24167935-ed55-4d7f-a6b3-f0df6fabda65 RestoreWorkspace: Default SaveWorkspace: Default diff --git a/data/test.data.rdata b/data/test.data.rdata old mode 100644 new mode 100755 diff --git a/data/train.data.rdata b/data/train.data.rdata old mode 100644 new mode 100755 diff --git a/inst/CITATION b/inst/CITATION old mode 100644 new mode 100755 diff --git a/man/addBanterDetector.Rd b/man/addBanterDetector.Rd old mode 100644 new mode 100755 diff --git a/man/banter-package.Rd b/man/banter-package.Rd old mode 100644 new mode 100755 index c972337..3ff05f2 --- a/man/banter-package.Rd +++ b/man/banter-package.Rd @@ -1,6 +1,5 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/banter-package.R -\docType{package} \name{banter-package} \alias{banter-package} \alias{banter} diff --git a/man/banterGuide.Rd b/man/banterGuide.Rd old mode 100644 new mode 100755 diff --git a/man/banter_detector-class.Rd b/man/banter_detector-class.Rd old mode 100644 new mode 100755 diff --git a/man/banter_model-class.Rd b/man/banter_model-class.Rd old mode 100644 new mode 100755 diff --git a/man/getBanterModel.Rd b/man/getBanterModel.Rd old mode 100644 new mode 100755 index b39f4be..2c9aec9 --- a/man/getBanterModel.Rd +++ b/man/getBanterModel.Rd @@ -13,7 +13,7 @@ getBanterModel(x, model = "event") to extract the event-level model. Can also be the name of a detector.} } \value{ -a \code{\link{randomForest}} model object. +a \code{\link[randomForest]{randomForest}} model object. } \description{ Extract BANTER event or detector Random Forest model. diff --git a/man/getBanterModelData.Rd b/man/getBanterModelData.Rd old mode 100644 new mode 100755 diff --git a/man/getDetectorNames.Rd b/man/getDetectorNames.Rd old mode 100644 new mode 100755 diff --git a/man/getSampSize.Rd b/man/getSampSize.Rd old mode 100644 new mode 100755 diff --git a/man/initBanterModel.Rd b/man/initBanterModel.Rd old mode 100644 new mode 100755 diff --git a/man/internals.Rd b/man/internals.Rd old mode 100644 new mode 100755 diff --git a/man/modelPctCorrect.Rd b/man/modelPctCorrect.Rd old mode 100644 new mode 100755 diff --git a/man/numCalls.Rd b/man/numCalls.Rd old mode 100644 new mode 100755 diff --git a/man/numEvents.Rd b/man/numEvents.Rd old mode 100644 new mode 100755 diff --git a/man/plotDetectorTrace.Rd b/man/plotDetectorTrace.Rd old mode 100644 new mode 100755 diff --git a/man/predict.Rd b/man/predict.Rd old mode 100644 new mode 100755 diff --git a/man/runBanterModel.Rd b/man/runBanterModel.Rd old mode 100644 new mode 100755 diff --git a/man/subsampleDetections.Rd b/man/subsampleDetections.Rd old mode 100644 new mode 100755 diff --git a/man/summary.Rd b/man/summary.Rd old mode 100644 new mode 100755 diff --git a/man/test.data.Rd b/man/test.data.Rd old mode 100644 new mode 100755 diff --git a/man/train.data.Rd b/man/train.data.Rd old mode 100644 new mode 100755 diff --git a/tests/testthat.R b/tests/testthat.R old mode 100644 new mode 100755 diff --git a/tests/testthat/test-accessors.R b/tests/testthat/test-accessors.R old mode 100644 new mode 100755 index 10b8e92..000c141 --- a/tests/testthat/test-accessors.R +++ b/tests/testthat/test-accessors.R @@ -1,7 +1,7 @@ context("model accessors") data(train.data) -mdl <- initBanterModel(train.data$events) %>% +mdl <- initBanterModel(train.data$events) |> addBanterDetector( train.data$detectors, ntree = 50, sampsize = 1, num.cores = 1 diff --git a/tests/testthat/test-init.R b/tests/testthat/test-init.R old mode 100644 new mode 100755 diff --git a/tests/testthat/test-numCalls b/tests/testthat/test-numCalls old mode 100644 new mode 100755 diff --git a/tests/testthat/test-summary b/tests/testthat/test-summary old mode 100644 new mode 100755 From 03c9a6b7bcd0c90efc14fc0b6a14adca4a6c8b19 Mon Sep 17 00:00:00 2001 From: ericarcher Date: Thu, 12 Jun 2025 01:34:00 -0700 Subject: [PATCH 2/2] v 0.9.8 on CRAN --- CRAN-SUBMISSION | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CRAN-SUBMISSION b/CRAN-SUBMISSION index 7be64fb..518d18c 100644 --- a/CRAN-SUBMISSION +++ b/CRAN-SUBMISSION @@ -1,3 +1,3 @@ -Version: 0.9.7 -Date: 2025-06-08 18:07:42 UTC -SHA: 173012c262e57fd8186d60d1ec794080453f2979 +Version: 0.9.8 +Date: 2025-06-11 04:11:57 UTC +SHA: bab66da242d793907acfe612a135d37e0aded140