From 0ebed6463addb012af53cbd9a57e97b3ae4b7e5a Mon Sep 17 00:00:00 2001 From: Sam Woodman - NOAA Date: Mon, 11 Aug 2025 15:55:19 -0700 Subject: [PATCH 1/6] Added das_spcodes_read, extdata, big doc updates --- .github/workflows/R-CMD-check.yaml | 2 +- DESCRIPTION | 3 +- NAMESPACE | 2 + NEWS.md | 9 + R/das_check.R | 35 +- R/das_chop_equallength.R | 4 +- R/das_chop_section.R | 4 +- R/das_comments.R | 2 +- R/das_effort.R | 111 +++---- R/das_effort_sight.R | 2 +- R/das_effort_strata.R | 47 ++- R/das_format_pdf.R | 24 +- R/das_intersects_strata.R | 56 ++-- R/das_process.R | 2 +- R/das_read.R | 42 +-- R/das_segdata.R | 75 ++--- R/das_sight.R | 150 +++++---- R/das_spcodes.R | 50 +++ R/distance_greatcircle.R | 2 +- R/randpicks_convert.R | 17 +- R/subsetting.R | 23 +- R/swfscDAS-package.R | 2 +- inst/{ => extdata}/Ship_sample.dat | 0 inst/{ => extdata}/SpCodes_sample.dat | 0 inst/{ => extdata}/das_sample.das | 0 inst/{ => extdata}/das_sample_randpicks.csv | 0 inst/{ => extdata}/das_sample_stratum.csv | 0 man/as_das_df.Rd | 8 +- man/as_das_dfr.Rd | 8 +- man/das_check.Rd | 119 +++---- man/das_chop_condition.Rd | 90 +++--- man/das_chop_equallength.Rd | 116 +++---- man/das_chop_section.Rd | 18 +- man/das_comments.Rd | 8 +- man/das_df-class.Rd | 108 +++---- man/das_dfr-class.Rd | 70 ++-- man/das_effort.Rd | 163 +++++----- man/das_effort_sight.Rd | 46 +-- man/das_effort_strata.Rd | 47 ++- man/das_format_pdf.Rd | 22 +- man/das_intersects_strata.Rd | 58 ++-- man/das_process.Rd | 172 +++++----- man/das_read.Rd | 106 +++--- man/das_segdata.Rd | 71 ++-- man/das_sight.Rd | 338 ++++++++++---------- man/das_spcodes.Rd | 38 +++ man/randpicks_convert.Rd | 15 +- man/subsetting.Rd | 23 +- tests/testthat/test-class.R | 4 +- tests/testthat/test-das_check.R | 6 +- tests/testthat/test-effort_strata.R | 6 +- tests/testthat/test-output.R | 2 +- tests/testthat/test-process.R | 2 +- tests/testthat/test-subsetting.R | 2 +- tests/testthat/test-zero_sighting_events.R | 2 +- vignettes/DAS_data_join.Rmd | 12 +- vignettes/swfscDAS.Rmd | 4 +- 57 files changed, 1245 insertions(+), 1103 deletions(-) create mode 100644 R/das_spcodes.R rename inst/{ => extdata}/Ship_sample.dat (100%) rename inst/{ => extdata}/SpCodes_sample.dat (100%) rename inst/{ => extdata}/das_sample.das (100%) rename inst/{ => extdata}/das_sample_randpicks.csv (100%) rename inst/{ => extdata}/das_sample_stratum.csv (100%) create mode 100644 man/das_spcodes.Rd diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 14159b7..494653a 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -2,7 +2,7 @@ # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help on: push: - branches: [main, master] + branches: [main, master, dev] pull_request: branches: [main, master] diff --git a/DESCRIPTION b/DESCRIPTION index fb2e489..acda560 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: swfscDAS Title: Processing DAS Data Files -Version: 0.6.4 +Version: 0.7.0.9000 Authors@R: person("Sam", "Woodman", email = "sam.woodman@noaa.gov", role = c("aut", "cre"), comment = c(ORCID = "0000-0001-6071-8186")) Description: Process and summarize DAS data files. @@ -31,5 +31,6 @@ Suggests: testthat (>= 2.1.0) License: Apache License (== 2) Encoding: UTF-8 +Roxygen: list(markdown = TRUE) RoxygenNote: 7.3.2 VignetteBuilder: knitr diff --git a/NAMESPACE b/NAMESPACE index a257432..5ec6ee0 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -54,6 +54,7 @@ export(das_process) export(das_read) export(das_segdata) export(das_sight) +export(das_spcodes_read) export(distance_greatcircle) export(randpicks_convert) importFrom(dplyr,add_row) @@ -97,6 +98,7 @@ importFrom(purrr,pmap_int) importFrom(purrr,pmap_lgl) importFrom(readr,col_character) importFrom(readr,cols) +importFrom(readr,fwf_cols) importFrom(readr,fwf_positions) importFrom(readr,read_fwf) importFrom(rlang,"!!") diff --git a/NEWS.md b/NEWS.md index cc4b8f8..80d8309 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,12 @@ +# swfscDAS 0.7.0.9000 + +* Added an exported function `das_spcodes_read` for consistent reading of shipboard SpCode files + +* Moved example data files to an 'extdata' folder within 'inst' + +* Update roxygen to use markdown + + # swfscDAS 0.6.4 * The DateTime column in `das_read` output now has a timezone of `""` (#13) diff --git a/R/das_check.R b/R/das_check.R index 51313ac..8fc09ca 100644 --- a/R/das_check.R +++ b/R/das_check.R @@ -6,9 +6,12 @@ #' @param skip integer: see \code{\link[readr]{read_fwf}}. Default is 0 #' @param file.out filename to which to write the error log; #' default is \code{NULL} -#' @param sp.codes character; filename of .dat file from which to read -#' accepted species codes. If \code{NULL}, species codes will not be checked. -#' Default is \code{NULL} +#' @param sp.codes.file character; default is `NULL`. +#' Filename of the SpCodes file from which to read the species codes. +#' If `NULL`, the default (internal) file will be used. +#' The SpCodes file will be read by [das_spcodes_read()] +#' @param sp.codes.skip integer; default is 0. +#' Passed directly to `skip` argument of [das_spcodes_read()] #' @param print.cruise.nums logical; indicates if a table with all the #' cruise numbers in the \code{x} should be printed using #' \code{\link[base]{table}}. Default is \code{TRUE} @@ -90,12 +93,18 @@ #' A warning is printed if any events are r events; see \code{\link{das_process}} for details about r events #' #' @examples -#' y <- system.file("das_sample.das", package = "swfscDAS") +#' y <- system.file("extdata", "das_sample.das", package = "swfscDAS") #' if (interactive()) das_check(y) #' #' @export -das_check <- function(file, skip = 0, file.out = NULL, sp.codes = NULL, - print.cruise.nums = TRUE) { +das_check <- function( + file, + skip = 0, + file.out = NULL, + sp.codes.file = NULL, + sp.codes.skip = 0, + print.cruise.nums = TRUE + ) { if (length(unique(file)) != length(file)) warning("Not all files are unique - this likely will cause an error in ", @@ -133,10 +142,10 @@ das_check <- function(file, skip = 0, file.out = NULL, sp.codes = NULL, #---------------------------------------------------------------------------- ### Process sp.codes file - if (!is.null(sp.codes)) { + if (!is.null(sp.codes.file)) { message("Reading and processing SpCodes file") sp.acc.df <- read_fwf( - sp.codes, + sp.codes.file, col_positions = fwf_positions(start = c(1, 6, 18, 58), end = c(4, 15, 57, NA)), col_types = cols(.default = col_character()), trim_ws = TRUE, skip = 0, skip_empty_rows = FALSE @@ -146,7 +155,7 @@ das_check <- function(file, skip = 0, file.out = NULL, sp.codes = NULL, sp.acc.all <- c(sp.acc, tolower(sp.acc)) if (!all(nchar(sp.acc) %in% 2:3)) - warning("Some species codes from sp.codes are not two or three charcters. ", + warning("Some species codes from sp.codes.file are not two or three charcters. ", "Did you load the correct species code .dat file?", immediate. = TRUE) } @@ -485,8 +494,8 @@ das_check <- function(file, skip = 0, file.out = NULL, sp.codes = NULL, idx.a.4 <- .check_character(x, "A", "Data4", c("N", "Y", "n", "y", NA)) txt.a.4 <- "Birds (Data4 of A events) is not one of N, Y, n, y, or NA" - txt.a.spcode <- "Species code(s) were not one of the accepted codes provided via sp.codes" - idx.a.spcode <- if (is.null(sp.codes)) { + txt.a.spcode <- "Species code(s) were not one of the accepted codes provided via sp.codes.file" + idx.a.spcode <- if (is.null(sp.codes.file)) { integer(0) } else { .check_character(x, "A", paste0("Data", 5:8), c(sp.acc.all, NA)) @@ -500,8 +509,8 @@ das_check <- function(file, skip = 0, file.out = NULL, sp.codes = NULL, ) # Turtle - txt.t.spcode <- "Turtle species code was not one of the accepted codes provided via sp.codes" - idx.t.spcode <- if (is.null(sp.codes)) { + txt.t.spcode <- "Turtle species code was not one of the accepted codes provided via sp.codes.file" + idx.t.spcode <- if (is.null(sp.codes.file)) { integer(0) } else { .check_character(x, "t", paste0("Data", 2), c(sp.acc.all, NA)) diff --git a/R/das_chop_equallength.R b/R/das_chop_equallength.R index 363d283..482c74c 100644 --- a/R/das_chop_equallength.R +++ b/R/das_chop_equallength.R @@ -74,8 +74,8 @@ #' \code{x} (i.e., using the same DAS data) in the future. Note that when #' saving with \code{\link[utils:read.table]{write.csv}}, users must specify #' \code{row.names = FALSE} so that the CSV file only has two columns. For an -#' example randpicks file, see \code{system.file("das_sample_randpicks.csv", -#' package = "swfscDAS")} +#' example randpicks file, see +#' `system.file("extdata", "das_sample_randpicks.csv", package = "swfscDAS")` #' #' If the column \code{dist_from_prev} does not exist, the distance between #' subsequent events is calculated as described in \code{\link{das_effort}} diff --git a/R/das_chop_section.R b/R/das_chop_section.R index 8ec6d10..5ed889f 100644 --- a/R/das_chop_section.R +++ b/R/das_chop_section.R @@ -23,10 +23,10 @@ #' See the Examples section for an example where the two methods give the same output. #' Note that the longest continuous effort section in the sample data is ~22km. #' -#' @return See \code{\link{das_chop_equallength}}. The randpicks values will all be \code{NA} +#' @return See [das_chop_equallength()]. The randpicks values will all be `NA` #' #' @examples -#' y <- system.file("das_sample.das", package = "swfscDAS") +#' y <- system.file("extdata", "das_sample.das", package = "swfscDAS") #' y.proc <- das_process(y) #' #' y.eff1 <- das_effort(y.proc, method = "equallength", seg.km = 25, num.cores = 1) diff --git a/R/das_comments.R b/R/das_comments.R index c09a14c..393fd76 100644 --- a/R/das_comments.R +++ b/R/das_comments.R @@ -13,7 +13,7 @@ #' comment_str containing the concatenated comment strings #' #' @examples -#' y <- system.file("das_sample.das", package = "swfscDAS") +#' y <- system.file("extdata", "das_sample.das", package = "swfscDAS") #' y.proc <- das_process(y) #' #' das_comments(y.proc) diff --git a/R/das_effort.R b/R/das_effort.R index e65b8c3..4827a90 100644 --- a/R/das_effort.R +++ b/R/das_effort.R @@ -39,65 +39,66 @@ #' @param ... arguments passed to the specified chopping function, such as #' \code{seg.km} or \code{seg.min.km} #' -#' @details This is the top-level function for chopping processed DAS data into -#' modeling segments (henceforth 'segments'), and assigning sightings and -#' related information (e.g., weather conditions) to each segment. This -#' function returns data frames with all relevant information for the effort -#' segments and associated sightings ('segdata' and 'sightinfo', -#' respectively). Before chopping, the DAS data is filtered for events (rows) -#' where either the 'OnEffort' column is \code{TRUE} or the 'Event' column -#' "E". In other words, the data is filtered for continuous effort sections -#' (henceforth 'effort sections'), where effort sections run from "R" to "E" -#' events (inclusive), and then passed to the chopping function specified -#' using \code{method}. Note that while B events immediately preceding an R -#' are on effort, they are ignored during effort chopping. In addition, all on -#' effort events (other than ? and numeric events) with \code{NA} DateTime, -#' Lat, or Lon values are verbosely removed. +#' @details +#' This is the top-level function for chopping processed DAS data into modeling +#' segments (henceforth 'segments'), and assigning sightings and related +#' information (e.g., weather conditions) to each segment. This function returns +#' data frames with all relevant information for the effort segments and +#' associated sightings ('segdata' and 'sightinfo', respectively). Before +#' chopping, the DAS data is filtered for events (rows) where either the +#' 'OnEffort' column is \code{TRUE} or the 'Event' column "E". In other words, +#' the data is filtered for continuous effort sections (henceforth 'effort +#' sections'), where effort sections run from "R" to "E" events (inclusive), and +#' then passed to the chopping function specified using \code{method}. Note that +#' while B events immediately preceding an R are on effort, they are ignored +#' during effort chopping. In addition, all on effort events (other than ? and +#' numeric events) with \code{NA} DateTime, Lat, or Lon values are verbosely +#' removed. #' -#' If \code{strata.files} is not \code{NULL}, then the effort lines will be -#' split by the user-provided stratum (strata). In this case, a column -#' 'stratum' will be added to the end of the segdata data frame with the -#' user-provided name of the stratum that the segment was in, or \code{NA} if -#' the segment was not in any of the strata. If no name was provided for the -#' stratum in \code{strata.files}, then the value will be "Stratum#", where -#' "#" is the index of the applicable stratum in \code{strata.files}. While -#' the user can provide as many strata as they want, these strata can share -#' boundaries but they cannot overlap. See \code{\link{das_effort_strata}} for -#' more details. +#' If \code{strata.files} is not \code{NULL}, then the effort lines will be +#' split by the user-provided stratum (strata). In this case, a column 'stratum' +#' will be added to the end of the segdata data frame with the user-provided +#' name of the stratum that the segment was in, or \code{NA} if the segment was +#' not in any of the strata. If no name was provided for the stratum in +#' \code{strata.files}, then the value will be "Stratum#", where "#" is the +#' index of the applicable stratum in \code{strata.files}. While the user can +#' provide as many strata as they want, these strata can share boundaries but +#' they cannot overlap. See \code{\link{das_effort_strata}} for more details. #' -#' The following chopping methods are currently available: "condition", -#' "equallength", and "section. When using the "condition" method, effort -#' sections are chopped into segments every time a condition changes, thereby -#' ensuring that the conditions are consistent across the entire segment. See -#' \code{\link{das_chop_condition}} for more details about this method, -#' including arguments that must be passed to it via the argument \code{...} +#' The following chopping methods are currently available: "condition", +#' "equallength", and "section. When using the "condition" method, effort +#' sections are chopped into segments every time a condition changes, thereby +#' ensuring that the conditions are consistent across the entire segment. See +#' \code{\link{das_chop_condition}} for more details about this method, +#' including arguments that must be passed to it via the argument \code{...} #' -#' The "equallength" method consists of chopping effort sections into -#' equal-length segments of length \code{seg.km}, and doing a weighted average -#' of the conditions for the length of that segment. See -#' \code{\link{das_chop_equallength}} for more details about this method, -#' including arguments that must be passed to it via the argument \code{...} +#' The "equallength" method consists of chopping effort sections into +#' equal-length segments of length \code{seg.km}, and doing a weighted average +#' of the conditions for the length of that segment. See +#' \code{\link{das_chop_equallength}} for more details about this method, +#' including arguments that must be passed to it via the argument \code{...} #' -#' The "section" method involves 'chopping' the effort into continuous effort -#' sections, i.e. each continuous effort section is a single effort segment. -#' See \code{\link{das_chop_section}} for more details about this method. +#' The "section" method involves 'chopping' the effort into continuous effort +#' sections, i.e. each continuous effort section is a single effort segment. See +#' \code{\link{das_chop_section}} for more details about this method. #' -#' The distance between the lat/lon points of subsequent events is calculated -#' using the method specified in \code{distance.method}. If "greatcircle", -#' \code{\link{distance_greatcircle}} is used, while -#' \code{\link[swfscMisc]{distance}} is used otherwise. See -#' \code{\link{das_sight}} for how the sightings are processed. +#' The distance between the lat/lon points of subsequent events is calculated +#' using the method specified in \code{distance.method}. If "greatcircle", +#' \code{\link{distance_greatcircle}} is used, while +#' \code{\link[swfscMisc]{distance}} is used otherwise. See +#' \code{\link{das_sight}} for how the sightings are processed. #' -#' The sightinfo data frame includes the column 'included', which is used in -#' \code{\link{das_effort_sight}} when summarizing the number of sightings and -#' animals for selected species. \code{\link{das_effort_sight}} is a separate -#' function to allow users to personalize the included values as desired for -#' their analysis. By default, i.e. in the output of this function, 'included' -#' is \code{TRUE} if: the sighting was made when on effort, by a standard -#' observer (see \code{\link{das_sight}}), and in a Beaufort sea state less -#' than or equal to five. +#' The sightinfo data frame includes the column 'included', which is used in +#' \code{\link{das_effort_sight}} when summarizing the number of sightings and +#' animals for selected species. \code{\link{das_effort_sight}} is a separate +#' function to allow users to personalize the included values as desired for +#' their analysis. By default, i.e. in the output of this function, 'included' +#' is \code{TRUE} if: the sighting was made when on effort, by a standard +#' observer (see \code{\link{das_sight}}), and in a Beaufort sea state less than +#' or equal to five. #' -#' @return List of three data frames: +#' @return +#' List of three data frames: #' \itemize{ #' \item segdata: one row for every segment, and columns for information #' including unique segment number (segnum), the corresponding effort @@ -123,7 +124,7 @@ #' \code{\link{das_chop_section}}, \code{\link{das_segdata}} #' #' @examples -#' y <- system.file("das_sample.das", package = "swfscDAS") +#' y <- system.file("extdata", "das_sample.das", package = "swfscDAS") #' y.proc <- das_process(y) #' #' # Using "condition" method @@ -137,14 +138,14 @@ #' #' \donttest{ #' # Using "equallength" method -#' y.rand <- system.file("das_sample_randpicks.csv", package = "swfscDAS") +#' y.rand <- system.file("extdata", "das_sample_randpicks.csv", package = "swfscDAS") #' das_effort( #' y.proc, method = "equallength", seg.km = 10, randpicks.load = y.rand, #' num.cores = 1 #' ) #' #' # Using "section" method and chop by strata -#' stratum.file <- system.file("das_sample_stratum.csv", package = "swfscDAS") +#' stratum.file <- system.file("extdata", "das_sample_stratum.csv", package = "swfscDAS") #' das_effort( #' y.proc, method = "section", strata.files = list(Poly1 = stratum.file), #' num.cores = 1 diff --git a/R/das_effort_sight.R b/R/das_effort_sight.R index 7fc7a70..86537e5 100644 --- a/R/das_effort_sight.R +++ b/R/das_effort_sight.R @@ -44,7 +44,7 @@ #' the sightings that were included in the effort segment summaries #' #' @examples -#' y <- system.file("das_sample.das", package = "swfscDAS") +#' y <- system.file("extdata", "das_sample.das", package = "swfscDAS") #' y.proc <- das_process(y) #' y.eff.cond <- das_effort( #' y.proc, method = "condition", conditions = "Bft", seg.min.km = 0.05, diff --git a/R/das_effort_strata.R b/R/das_effort_strata.R index dcfd4f5..c3a6e39 100644 --- a/R/das_effort_strata.R +++ b/R/das_effort_strata.R @@ -6,32 +6,31 @@ #' or a data frame that can be coerced to class \code{das_df} #' @param ... ignored #' @param strata.files list of path(s) of the stratum CSV file(s); -#' see \code{\link{das_effort}} +#' see [das_effort()] #' -#' @details This function should only be called by \code{\link{das_effort}}, -#' i.e. it should not be called by users in their personal scripts. -#' Practically speaking, this functions splits the effort line wherever it crosses a stratum line. -#' This point of intersection is interpolated; -#' specifically, it is determined using \code{\link[sf:geos_binary_ops]{st_intersection}}. -#' Thus, any effort will be first split at these effort-stratum boundary intersection points, -#' and then using the specified method (e.g. condition). +#' @details +#' This function should only be called by [das_effort()], i.e. it +#' should not be called by users in their personal scripts. Practically +#' speaking, this functions splits the effort line wherever it crosses a stratum +#' line. This point of intersection is interpolated; specifically, it is +#' determined using [sf::st_intersection()]. Thus, any effort will be first +#' split at these effort-stratum boundary intersection points, and then using +#' the specified method (e.g. condition). #' -#' @return The data frame x, with 1) columns added that -#' indicate a) if the point was in a particular stratum (see \code{\link{das_intersects_strata}}), and -#' b) the index of the stratum in \code{strata.files} -#' (column name 'stratum'; 0 if the point intersects with no strata), and -#' 2) two rows added for each strata crossing -#' that occurs between something other than an E and R. -#' These rows are necessary because of how \code{das_effort} processes effort. -#' The added rows are the same as the event previous to the strata crossing, except: -#' \itemize{ -#' \item They have the event code "strataE" and "strataR", respectively -#' \item Their coordinates are the coordinates of the intersection of -#' the effort line and the stratum boundary -#' \item Their 'idx_eff' values are plus 0.4 and 0.5, respectively -#' \item The second added row has the same stratum info as the point -#' immediately after the stratum boundary crossing -#' } +#' @return +#' The data frame x, with 1) columns added that indicate a) if the point was in +#' a particular stratum (see [das_intersects_strata()]), and b) the index of the +#' stratum in \code{strata.files} (column name 'stratum'; 0 if the point +#' intersects with no strata), and 2) two rows added for each strata crossing +#' that occurs between something other than an E and R. These rows are necessary +#' because of how \code{das_effort} processes effort. The added rows are the +#' same as the event previous to the strata crossing, except: +#' * They have the event code "strataE" and "strataR", respectively +#' * Their coordinates are the coordinates of the intersection of +#' the effort line and the stratum boundary +#' * Their 'idx_eff' values are plus 0.4 and 0.5, respectively +#' * The second added row has the same stratum info as the point +#' immediately after the stratum boundary crossing das_effort_strata <- function(x, ...) UseMethod("das_effort_strata") diff --git a/R/das_format_pdf.R b/R/das_format_pdf.R index 84b1813..0fa9bd9 100644 --- a/R/das_format_pdf.R +++ b/R/das_format_pdf.R @@ -1,20 +1,24 @@ #' DAS format requirements #' -#' Save the PDF document describing the DAS format required by \code{swfscDAS} to a specified file +#' Save the PDF document describing the DAS format required by \code{swfscDAS} +#' to a specified file #' #' @param file character, the name of the file where the PDF will be saved -#' @param ... passed on to \code{\link[base:files]{file.copy}}; might included named argument \code{overwrite} +#' @param ... passed on to [base::file.copy()]; +#' might included named argument \code{overwrite} #' -#' @details A wrapper function for \code{\link[base:files]{file.copy}}. -#' This function saves the PDF document describing the DAS data format requirements by -#' copying the PDF document located at \code{system.file("DAS_Format.pdf", package = "swfscDAS")} -#' to \code{file} +#' @details +#' A wrapper function for [base::file.copy()]. This function saves the PDF +#' document describing the DAS data format requirements by copying the PDF +#' document located at`system.file("DAS_Format.pdf", package = "swfscDAS")` to +#' `file` #' -#' This file can also be downloaded from -#' \url{https://github.com/swfsc/swfscDAS/blob/master/inst/DAS_Format.pdf} +#' This file can also be downloaded from +#' #' -#' @return output of \code{\link[base:files]{file.copy}}; -#' \code{TRUE} if writing of file was successful, and \code{FALSE} otherwise +#' @return +#' output of [base::file.copy()]; \code{TRUE} if writing of file was successful, +#' and \code{FALSE} otherwise #' #' @examples #' das_format_pdf(file.path(tempdir(), "DAS_Format.pdf"), overwrite = FALSE) diff --git a/R/das_intersects_strata.R b/R/das_intersects_strata.R index e5c76fa..00e16b6 100644 --- a/R/das_intersects_strata.R +++ b/R/das_intersects_strata.R @@ -20,42 +20,44 @@ #' Ignored if \code{x} is a list; default is \code{FALSE}. #' See 'Value' section for more details #' -#' @details Assigns DAS event points or segment midpoints to strata polygons -#' using \code{\link[sf:geos_binary_pred]{st_intersects}}. +#' @details +#' Assigns DAS event points or segment midpoints to strata polygons using +#' [sf::st_intersects()]. #' -#' If \code{x} is a list, then 1) it must be the output of -#' \code{\link{das_effort}} or \code{\link{das_effort_sight}} and -#' 2) the segment midpoints (column names mlon and mlat, respectively) -#' are the points checked if they intersect with each provided stratum. -#' If \code{x} is a data frame, then the user must provide the columns -#' that specify the point coordinates to check. +#' If \code{x} is a list, then 1) it must be the output of +#' \code{\link{das_effort}} or \code{\link{das_effort_sight}} and 2) the segment +#' midpoints (column names mlon and mlat, respectively) are the points checked +#' if they intersect with each provided stratum. If \code{x} is a data frame, +#' then the user must provide the columns that specify the point coordinates to +#' check. #' -#' \code{x} should not be an object of class \code{das_dfr}, -#' or an object of class \code{das_df} created with \code{add.dtll.sight = FALSE}, -#' because the ? and numeric event codes will have NA latitude and longitude values. +#' \code{x} should not be an object of class \code{das_dfr}, or an object of +#' class \code{das_df} created with \code{add.dtll.sight = FALSE}, because the ? +#' and numeric event codes will have NA latitude and longitude values. #' -#' @return If \code{x} is a data frame, then logical columns are added to \code{x} -#' indicating if each point intersected with the corresponding stratum polygon. -#' The names of these columns are the names of \code{strata.files}; -#' the element(s) of \code{strata.files} will have the name InPoly#, -#' where '#' is the index of that stratum polygon in \code{strata.files}. -#' If \code{strata.which}, then the column 'strata_which' is added to the end of the data frame. -#' This column contains either a 0 if the point intersects with no strata or -#' 2) a numeric indicating the index (in \code{strata.files}) of -#' the (first) strata polygon that the point intersects with. +#' @return +#' If \code{x} is a data frame, then logical columns are added to \code{x} +#' indicating if each point intersected with the corresponding stratum polygon. +#' The names of these columns are the names of \code{strata.files}; the +#' element(s) of \code{strata.files} will have the name InPoly#, where '#' is +#' the index of that stratum polygon in \code{strata.files}. If +#' \code{strata.which}, then the column 'strata_which' is added to the end of +#' the data frame. This column contains either a 0 if the point intersects with +#' no strata or 2) a numeric indicating the index (in \code{strata.files}) of +#' the (first) strata polygon that the point intersects with. #' -#' Otherwise, i.e. if \code{x} is a list and thus the output of one of the effort functions, -#' then the stratum columns are added to both the segdata and sightinfo data frames. -#' However, note that the columns added to the sightinfo data frame still indicate -#' whether or not the segment midpoint was in the corresponding stratum, -#' rather than the sighting point itself. +#' Otherwise, i.e. if \code{x} is a list and thus the output of one of the +#' effort functions, then the stratum columns are added to both the segdata and +#' sightinfo data frames. However, note that the columns added to the sightinfo +#' data frame still indicate whether or not the segment midpoint was in the +#' corresponding stratum, rather than the sighting point itself. #' #' @examples -#' y <- system.file("das_sample.das", package = "swfscDAS") +#' y <- system.file("extdata", "das_sample.das", package = "swfscDAS") #' y.proc <- das_process(y) #' y.eff <- das_effort(y.proc, method = "section", num.cores = 1) #' -#' stratum.file <- system.file("das_sample_stratum.csv", package = "swfscDAS") +#' stratum.file <- system.file("extdata", "das_sample_stratum.csv", package = "swfscDAS") #' das_intersects_strata(y.eff, list(InPoly = stratum.file), x.lon = "Lon", x.lat = "Lat") #' #' das_intersects_strata(y.proc, list(stratum.file)) diff --git a/R/das_process.R b/R/das_process.R index 96b652c..461ec7d 100644 --- a/R/das_process.R +++ b/R/das_process.R @@ -122,7 +122,7 @@ #' of R and E events #' #' @examples -#' y <- system.file("das_sample.das", package = "swfscDAS") +#' y <- system.file("extdata", "das_sample.das", package = "swfscDAS") #' das_process(y) #' #' y.read <- das_read(y) diff --git a/R/das_read.R b/R/das_read.R index 438e176..7e1bcc1 100644 --- a/R/das_read.R +++ b/R/das_read.R @@ -4,15 +4,15 @@ #' data frame, where each line is data for a specific event #' #' @param file file name(s) of one or more DAS files -#' @param skip integer; see \code{\link[readr]{read_fwf}}. Default is 0 +#' @param skip integer; see [readr::read_fwf()]. Default is 0 #' @param ... ignored #' -#' @details Reads/parses DAS data into columns of a data frame. -#' If \code{file} contains multiple file names, then the individual -#' data frames will be concatenated. +#' @details +#' Reads/parses DAS data into columns of a data frame. If \code{file} contains +#' multiple file names, then the individual data frames will be concatenated. #' -#' The provided DAS file must adhere to the following column number and format -#' specifications: +#' The provided DAS file must adhere to the following column number and format +#' specifications: #' \tabular{lrr}{ #' \emph{Item} \tab \emph{Columns} \tab \emph{Format}\cr #' Event number \tab 1-3 \tab \cr @@ -36,12 +36,14 @@ #' Data12 \tab 95+ \tab \cr #' } #' -#' See \code{\link{das_format_pdf}} for more information about DAS format requirements, and -#' note that 'Data#' columns may be referred to as 'Field#' columns in other documentation. +#' See \code{\link{das_format_pdf}} for more information about DAS format +#' requirements, and note that 'Data#' columns may be referred to as 'Field#' +#' columns in other documentation. #' -#' @return A \code{das_dfr} object, which is also a data frame, with DAS data -#' read into columns. The data are read into the data frame as characters as -#' described in 'Details', with the following exceptions: +#' @return +#' A \code{das_dfr} object, which is also a data frame, with DAS data read into +#' columns. The data are read into the data frame as characters as described in +#' 'Details', with the following exceptions: #' \tabular{lll}{ #' \emph{Name} \tab \emph{Class} \tab \emph{Details}\cr #' EffortDot \tab logical \tab \code{TRUE} if "." was present, and \code{FALSE} otherwise\cr @@ -54,18 +56,18 @@ #' line_num \tab integer \tab line number of each data row\cr #' } #' -#' DateTime values have a time zone value (i.e., a tzone attribute) of "". -#' Note that this means RStudio will print these datetimes with the local -#' timezone See the OffsetGMT column from \code{\link{das_process}} for -#' relevant time zone information +#' DateTime values have a time zone value (i.e., a tzone attribute) of "". Note +#' that this means RStudio will print these datetimes with the local timezone +#' See the OffsetGMT column from \code{\link{das_process}} for relevant time +#' zone information #' -#' Warnings are printed if any unexpected events have \code{NA} -#' DateTime/Lat/Lon values, or if any Lat/Lon values cannot be converted to -#' numeric values. Events that are 'expected' to have \code{NA} -#' DateTime/Lat/Lon values are: C, ?, 1, 2, 3, 4, 5, 6, 7, 8 +#' Warnings are printed if any unexpected events have \code{NA} DateTime/Lat/Lon +#' values, or if any Lat/Lon values cannot be converted to numeric values. +#' Events that are 'expected' to have \code{NA} DateTime/Lat/Lon values are: C, +#' ?, 1, 2, 3, 4, 5, 6, 7, 8 #' #' @examples -#' y <- system.file("das_sample.das", package = "swfscDAS") +#' y <- system.file("extdata", "das_sample.das", package = "swfscDAS") #' das_read(y) #' #' @export diff --git a/R/das_segdata.R b/R/das_segdata.R index d47ff70..a3a73ca 100644 --- a/R/das_segdata.R +++ b/R/das_segdata.R @@ -16,49 +16,50 @@ #' section) #' @param ... ignored #' -#' @details WARNING - do not call this function directly! It is exported for -#' documentation purposes, but is intended for internal package use only. +#' @details +#' WARNING - do not call this function directly! It is exported for +#' documentation purposes, but is intended for internal package use only. #' -#' This function was designed to be called by one of the das_chop_ functions, -#' e.g. \code{\link{das_chop_equallength}}, and thus users should avoid -#' calling it themselves. It loops through the events in \code{x}, chopping -#' \code{x} into modeling segments while calculating and storing relevant -#' information for each segment. Because \code{x} is a continuous effort -#' section, it must begin with a "B" or "R" event and end with the -#' corresponding "E" event. +#' This function was designed to be called by one of the das_chop_ functions, +#' e.g. \code{\link{das_chop_equallength}}, and thus users should avoid calling +#' it themselves. It loops through the events in \code{x}, chopping \code{x} +#' into modeling segments while calculating and storing relevant information for +#' each segment. Because \code{x} is a continuous effort section, it must begin +#' with a "B" or "R" event and end with the corresponding "E" event. #' -#' For each segment, this function reports the segment number, segment ID, -#' cruise number, the start/end/mid coordinates (lat/lon), start/end/mid -#' date/times (DateTime), segment length, year, month, day, midpoint time, -#' mode, OffsetGMT value, effort type, effective strip width sides (number of -#' sides searched), and average conditions (which are specified by -#' \code{conditions}). The segment ID is designated as \code{section.id} _ -#' index of the modeling segment. Thus, if \code{section.id} is \code{1}, then -#' the segment ID for the second segment from \code{x} is \code{"1_2"}. The -#' start/end coordinates and date/times are interpolated as needed, e.g. when -#' using the 'equallength' method. +#' For each segment, this function reports the segment number, segment ID, +#' cruise number, the start/end/mid coordinates (lat/lon), start/end/mid +#' date/times (DateTime), segment length, year, month, day, midpoint time, mode, +#' OffsetGMT value, effort type, effective strip width sides (number of sides +#' searched), and average conditions (which are specified by \code{conditions}). +#' The segment ID is designated as \code{section.id} _ index of the modeling +#' segment. Thus, if \code{section.id} is \code{1}, then the segment ID for the +#' second segment from \code{x} is \code{"1_2"}. The start/end coordinates and +#' date/times are interpolated as needed, e.g. when using the 'equallength' +#' method. #' -#' When \code{segdata.method} is "avg", the condition values are calculated as -#' a weighted average by distance. The reported value for logical columns -#' (e.g. Glare) is the percentage (in decimals) of the segment in which that -#' condition was \code{TRUE}. For character columns, the reported value for -#' each segment is the unique value(s) present in the segment, with \code{NA}s -#' omitted, pasted together via \code{paste(..., collapse = "; ")}. When -#' \code{segdata.method} is "maxdist", the reported values are, for each -#' condition, the value recorded for the longest distance during that segment -#' (with \code{NA}s omitted). +#' When \code{segdata.method} is "avg", the condition values are calculated as a +#' weighted average by distance. The reported value for logical columns (e.g. +#' Glare) is the percentage (in decimals) of the segment in which that condition +#' was \code{TRUE}. For character columns, the reported value for each segment +#' is the unique value(s) present in the segment, with \code{NA}s omitted, +#' pasted together via \code{paste(..., collapse = "; ")}. When +#' \code{segdata.method} is "maxdist", the reported values are, for each +#' condition, the value recorded for the longest distance during that segment +#' (with \code{NA}s omitted). #' -#' Cruise number, mode, effort type, sides searched, and file name are also -#' included in the segdata output. These values (excluding \code{NA}s) must be -#' consistent across the entire effort section, and thus across all segments -#' in \code{x}; a warning is printed if there are any inconsistencies +#' Cruise number, mode, effort type, sides searched, and file name are also +#' included in the segdata output. These values (excluding \code{NA}s) must be +#' consistent across the entire effort section, and thus across all segments in +#' \code{x}; a warning is printed if there are any inconsistencies #' -#' \code{\link[swfscMisc]{bearing}} and \code{\link[swfscMisc]{destination}} -#' are used to calculate the segment start, mid, and end points, with -#' \code{method = "vincenty"}. +#' \code{\link[swfscMisc]{bearing}} and \code{\link[swfscMisc]{destination}} are +#' used to calculate the segment start, mid, and end points, with \code{method = +#' "vincenty"}. #' -#' @return Data frame with the segdata information described in Details -#' and in \code{\link{das_effort}} +#' @return +#' Data frame with the segdata information described in Details and in +#' \code{\link{das_effort}} #' #' @export das_segdata <- function(x, ...) UseMethod("das_segdata") diff --git a/R/das_sight.R b/R/das_sight.R index 836a9a9..4037bae 100644 --- a/R/das_sight.R +++ b/R/das_sight.R @@ -11,34 +11,33 @@ #' Must be one or more of: "S", "K", "M", "G", "s", "k", "m", "g", "t", "p", "F" #' (case-sensitive). The default is all of these event codes #' -#' @details DAS events contain specific information in the 'Data#' columns, -#' with the information depending on the event code for that row. -#' The output data frame contains columns with this specific information -#' extracted to dedicated columns as described below. -#' This function recognizes the following types of sightings: -#' marine mammal sightings (event codes "S", "K", or "M"), -#' marine mammal resights (codes "s", "k", "m"), -#' marine mammal subgroup sightings (code "G"), -#' marine mammal subgroup resights (code "g"), -#' turtle sightings (code "t"), -#' pinniped sightings (code "p"), -#' and fishing vessel sightings (code "F"). -#' Warnings are printed if all S, K, M, and G events (and only these events) are not -#' followed by an A event and at least one numeric event. -#' See \code{\link{das_format_pdf}} for more information about events and event formats. -#' Of specific note - sperm whale sightings (species code 046) often contain additional estimates -#' recorded as "C" events immediately following the S, A, and numeric events. -#' Because these estimates are recorded as"C" events, they are NOT included in the -#' \code{das_sight} calculations or output for any \code{return.format} +#' @details +#' DAS events contain specific information in the 'Data#' columns, with the +#' information depending on the event code for that row. The output data frame +#' contains columns with this specific information extracted to dedicated +#' columns as described below. This function recognizes the following types of +#' sightings: marine mammal sightings (event codes "S", "K", or "M"), marine +#' mammal resights (codes "s", "k", "m"), marine mammal subgroup sightings (code +#' "G"), marine mammal subgroup resights (code "g"), turtle sightings (code +#' "t"), pinniped sightings (code "p"), and fishing vessel sightings (code "F"). +#' Warnings are printed if all S, K, M, and G events (and only these events) are +#' not followed by an A event and at least one numeric event. See +#' \code{\link{das_format_pdf}} for more information about events and event +#' formats. Of specific note - sperm whale sightings (species code 046) often +#' contain additional estimates recorded as "C" events immediately following the +#' S, A, and numeric events. Because these estimates are recorded as"C" events, +#' they are NOT included in the \code{das_sight} calculations or output for any +#' \code{return.format} #' -#' The \code{return.events} argument simply provides a shortcut for -#' filtering the output of \code{das_sight} by event codes +#' The \code{return.events} argument simply provides a shortcut for filtering +#' the output of \code{das_sight} by event codes #' -#' Abbreviations used in output column names: Gs = group size, Sp = species, -#' Nm = nautical mile, Perc = percentage, Prob = probable, -#' GsSchool = school-level group size info +#' Abbreviations used in output column names: Gs = group size, Sp = species, Nm +#' = nautical mile, Perc = percentage, Prob = probable, GsSchool = school-level +#' group size info #' -#' This function makes the following assumptions, and alterations to the raw DAS data: +#' This function makes the following assumptions, and alterations to the raw DAS +#' data: #' \itemize{ #' \item "A" events immediately following an S/K/M/G event have #' the same sighting number (Data1 value) as the S/K/M/G event @@ -57,16 +56,18 @@ #' 'TurtleAge', and 'TurtleCapt' #' } #' -#' @return Data frame with 1) the columns from \code{x}, excluding the 'Data#' columns, -#' and 2) columns with sighting information extracted from 'Data#' columns. -#' See \code{\link{das_format_pdf}} for more information the sighting information. -#' If \code{return.format} is "default", then there is one row for each species of each sighting event; -#' if \code{return.format} is "wide", then there is one row for each sighting event; -#' if \code{return.format} is "complete", then there is one row for every -#' group size estimate for each sighting event (excluding sperm whale "C" events - see the Details section). +#' @return +#' Data frame with 1) the columns from \code{x}, excluding the 'Data#' columns, +#' and 2) columns with sighting information extracted from 'Data#' columns. See +#' \code{\link{das_format_pdf}} for more information the sighting information. +#' If \code{return.format} is "default", then there is one row for each species +#' of each sighting event; if \code{return.format} is "wide", then there is one +#' row for each sighting event; if \code{return.format} is "complete", then +#' there is one row for every group size estimate for each sighting event +#' (excluding sperm whale "C" events - see the Details section). #' -#' The format-specific columns are described in their respective sections. -#' The following sighting information columns are included in all return formats: +#' The format-specific columns are described in their respective sections. The +#' following sighting information columns are included in all return formats: #' #' \tabular{lll}{ #' \emph{Sighting information} \tab \emph{Column name} \tab \emph{Notes} \cr @@ -97,26 +98,31 @@ #' Perpendicular distance (km) to sighting \tab PerpDistKm \tab Calculated via \code{(abs(sin(Bearing*pi/180) * DistNm) * 1.852)} #' } #' -#' SightNoDaily is a running count of the number of S/K/M/G sightings that occurred on each day. -#' It is formatted as 'YYYYMMDD'_'running count', e.g. "20050101_1". +#' SightNoDaily is a running count of the number of S/K/M/G sightings that +#' occurred on each day. It is formatted as 'YYYYMMDD'_'running count', e.g. +#' "20050101_1". #' -#' The GsSchoolBest, GsSchoolHigh, and GsSchoolLow columns are either: -#' 1) the arithmetic mean across observer estimates, for the "default" and "wide" formats, or -#' 2) the individual observer estimates, for the "complete" format. -#' Note that for non-"complete" formats, \code{na.rm = TRUE} is used when calculating the mean, -#' and thus blank elements of estimates (but not the whole incomplete estimate) are ignored. +#' The GsSchoolBest, GsSchoolHigh, and GsSchoolLow columns are either: 1) the +#' arithmetic mean across observer estimates, for the "default" and "wide" +#' formats, or 2) the individual observer estimates, for the "complete" format. +#' Note that for non-"complete" formats, \code{na.rm = TRUE} is used when +#' calculating the mean, and thus blank elements of estimates (but not the whole +#' incomplete estimate) are ignored. #' -#' To convert the perpendicular distance back to nautical miles, -#' one would divide PerpDistKm by 1.852 +#' To convert the perpendicular distance back to nautical miles, one would +#' divide PerpDistKm by 1.852 #' #' @section The "default" format output: -#' This output data frame contains 'long' sighting data, meaning there is one row for each species of each sighting event. -#' The GsSp... columns are calculated as follows: -#' for each species and for each observer estimate, the best/high/low school size estimate is multiplied by the applicable species percent estimate. -#' The values are grouped by species and then averaged to get single GsSpBest, GsSpHigh, and GsSpLow values for each species. -#' (using \code{\link[base]{mean}} with \code{na.rm = TRUE}) +#' This output data frame contains 'long' sighting data, meaning there is one +#' row for each species of each sighting event. The GsSp... columns are +#' calculated as follows: for each species and for each observer estimate, the +#' best/high/low school size estimate is multiplied by the applicable species +#' percent estimate. The values are grouped by species and then averaged to get +#' single GsSpBest, GsSpHigh, and GsSpLow values for each species. (using +#' \code{\link[base]{mean}} with \code{na.rm = TRUE}) #' -#' Sighting information columns/formats present specifically in the "default" format output: +#' Sighting information columns/formats present specifically in the "default" +#' format output: #' \tabular{lll}{ #' \emph{Sighting information} \tab \emph{Column name} \tab \emph{Notes}\cr #' Species code \tab SpCode \tab Boat type or mammal, turtle, or pinniped species codes\cr @@ -129,24 +135,26 @@ #' The product of the arithmetic means of GsSchoolLow and the corresponding species percentage\cr #' } #' -#' Note that for the above calculations, -#' the GsSchoolX value and corresponding species percentages were each -#' averaged across observers, using \code{na.rm = TRUE}, -#' before being multiplied to calculate GsSpX. For example, in the workflow: -#' \code{GsSpBest1 = mean(.data$Data2, na.rm = TRUE) * mean(.data$Data5, na.rm = TRUE)} +#' Note that for the above calculations, the GsSchoolX value and corresponding +#' species percentages were each averaged across observers, using \code{na.rm +#' = TRUE}, before being multiplied to calculate GsSpX. For example, in the +#' workflow: \code{GsSpBest1 = mean(.data$Data2, na.rm = TRUE) * +#' mean(.data$Data5, na.rm = TRUE)} #' #' @section The "wide" and "complete" format outputs: -#' The "wide" and "complete" options have very similar columns in their output date frames. -#' There are two main differences: 1) the "wide" format has one row for each sighting event, -#' while the complete format has a row for every observer estimate for each sightings, and thus -#' 2) in the "wide" format, all numeric information for which there are multiple observer estimates -#' (school group size, species percentage, etc.) are averaged across estimated via -#' an arithmetic mean (using \code{\link[base]{mean}} with \code{na.rm = TRUE}) +#' The "wide" and "complete" options have very similar columns in their output +#' date frames. There are two main differences: 1) the "wide" format has one row +#' for each sighting event, while the complete format has a row for every +#' observer estimate for each sightings, and thus 2) in the "wide" format, all +#' numeric information for which there are multiple observer estimates (school +#' group size, species percentage, etc.) are averaged across estimated via an +#' arithmetic mean (using \code{\link[base]{mean}} with \code{na.rm = TRUE}) #' -#' With these formats, note that the species/type code and group size for -#' turtle, pinniped, and boat sightings are in their own column +#' With these formats, note that the species/type code and group size for +#' turtle, pinniped, and boat sightings are in their own column #' -#' Sighting information columns present in the "wide" and "complete" format outputs: +#' Sighting information columns present in the "wide" and "complete" format +#' outputs: #' \tabular{lll}{ #' \emph{Sighting information} \tab \emph{Column name} \tab \emph{Notes} \cr #' Observer code - estimate \tab ObsEstimate \tab See below \cr @@ -175,16 +183,16 @@ #' Number of boats \tab BoatGs \tab \code{NA} for non-"F" events #' } #' -#' ObsEstimate refers to the code of the observer that made the corresponding estimate. -#' For the "wide" format, ObsEstimate is a list-column of all of the observer codes -#' that provided an estimate. -#' Also in the "wide" format, the GsSpBest# columns are the product of -#' the means of GsSchoolBest and the corresponding species percentage -#' (see the Default section for calculation details). -#' These numbers, 1 to 4, correspond to the order of the data as it appears in the DAS file +#' ObsEstimate refers to the code of the observer that made the corresponding +#' estimate. For the "wide" format, ObsEstimate is a list-column of all of the +#' observer codes that provided an estimate. Also in the "wide" format, the +#' GsSpBest# columns are the product of the means of GsSchoolBest and the +#' corresponding species percentage (see the Default section for calculation +#' details). These numbers, 1 to 4, correspond to the order of the data as it +#' appears in the DAS file #' #' @examples -#' y <- system.file("das_sample.das", package = "swfscDAS") +#' y <- system.file("extdata", "das_sample.das", package = "swfscDAS") #' y.proc <- das_process(y) #' #' das_sight(y.proc) diff --git a/R/das_spcodes.R b/R/das_spcodes.R new file mode 100644 index 0000000..7e6f1b4 --- /dev/null +++ b/R/das_spcodes.R @@ -0,0 +1,50 @@ +#' Read DAS SpCodes file +#' +#' Read DAS SpCodes file +#' +#' @name das_spcodes +#' +#' @param file character; filename of .dat file from which to read +#' species codes +#' @param skip integer; default is 3. +#' Number of lines to skip when reading SpCodes file. +#' See [readr::read_fwf()] for more details +#' +#' @details +#' Provide a standardized function to read a shipboard DAS SpCodes file. +#' Methods described in 'returns' +#' +#' @returns Data frame with four columns: +#' * SpCode: species code, columns 1 to 4 +#' * Abbr: species abbreviation, columns 6 to 15 +#' * SciName: species scientific name, columns 18 to 57 +#' * CommonName: species common name, columns 58 until the end of the line +#' +#' @examples +#' sp.codes.file <- system.file("extdata", "SpCodes_sample.dat", package = "swfscDAS") +#' das_spcodes_read(sp.codes.file) +#' +#' @export +das_spcodes_read <- function(file, skip = 0) { + read_fwf( + file, + # col_positions = fwf_positions(start = c(1, 10, 43), end = c(6, 42, NA)), + col_positions = fwf_cols( + SpCode = c(1, 4), + Abbr = c(6, 15), + SciName = c(18, 57), + CommonName = c(58, NA_integer_) + ), + col_types = cols(.default = col_character()), + trim_ws = TRUE, + skip = skip, + skip_empty_rows = FALSE + ) + + # sp.acc.df <- read_fwf( + # sp.codes, + # col_positions = fwf_positions(start = c(1, 6, 18, 58), end = c(4, 15, 57, NA)), + # col_types = cols(.default = col_character()), + # trim_ws = TRUE, skip = 0, skip_empty_rows = FALSE + # ) +} diff --git a/R/distance_greatcircle.R b/R/distance_greatcircle.R index 9ee76df..9eac47a 100644 --- a/R/distance_greatcircle.R +++ b/R/distance_greatcircle.R @@ -9,7 +9,7 @@ #' #' @return Distance in kilometers between lat1/lon1 and lat2/lon2 #' -#' @seealso \url{https://en.wikipedia.org/wiki/Great-circle_distance} +#' @seealso #' #' @export distance_greatcircle <- function(lat1, lon1, lat2, lon2) { diff --git a/R/randpicks_convert.R b/R/randpicks_convert.R index 34f194f..b75dc63 100644 --- a/R/randpicks_convert.R +++ b/R/randpicks_convert.R @@ -7,14 +7,17 @@ #' @param x.segdata Data frame; segdata that corresponds to \code{x.randpicks} #' @param seg.km numeric; target segment length used when creating \code{x.segdata} #' -#' @details Past DAS processing code (segchopr) only recorded the generated random values, -#' whereas swfscDAS randpicks files contain one line for each continuous effort section. -#' See \code{\link{das_chop_equallength}} for more details about the swfscDAS randpicks format. -#' This function 'converts' a randpicks data frame generated by segchopr -#' to a data frame that meets the swfscDAS randpicks format requirements +#' @details +#' Past DAS processing code (segchopr) only recorded the generated random +#' values, whereas swfscDAS randpicks files contain one line for each continuous +#' effort section. See \code{\link{das_chop_equallength}} for more details about +#' the swfscDAS randpicks format. This function 'converts' a randpicks data +#' frame generated by segchopr to a data frame that meets the swfscDAS randpicks +#' format requirements #' -#' @return Data frame with one line for each continuous effort section in \code{x.segdata}, -#' and two columns: \code{effort_section} and \code{randpicks} +#' @return +#' Data frame with one line for each continuous effort section in +#' \code{x.segdata}, and two columns: \code{effort_section} and \code{randpicks} #' #' @export randpicks_convert <- function(x.randpicks, x.segdata, seg.km) { diff --git a/R/subsetting.R b/R/subsetting.R index 416a8ff..920411d 100644 --- a/R/subsetting.R +++ b/R/subsetting.R @@ -9,21 +9,22 @@ #' @param value A suitable replacement value, see \code{\link[base]{[.data.frame}} #' #' @details -#' When subsetting a \code{das_dfr} or \code{das_df} object, henceforth a \code{das_} object, -#' using any of the functions described in \code{\link[base]{[.data.frame}}, -#' then then the \code{das_} class is simply dropped and the object is of class \code{data.frame}. -#' This is because of the strict format requirements of \code{das_} objects; -#' it is likely that a subsetted \code{das_} object will not have -#' the format required by subsequent swfscDAS functions, -#' and thus it is safest to drop the \code{das_} class. -#' If a data frame is passed to downstream \code{swfscDAS} functions that require a \code{das_} object, -#' then they will attempt to coerce the object to the necessary \code{das_} class -#' See \code{\link{as_das_dfr}} and \code{\link{as_das_df}} for more details. +#' When subsetting a \code{das_dfr} or \code{das_df} object, henceforth a +#' \code{das_} object, using any of the functions described in +#' \code{\link[base]{[.data.frame}}, then then the \code{das_} class is simply +#' dropped and the object is of class \code{data.frame}. This is because of the +#' strict format requirements of \code{das_} objects; it is likely that a +#' subsetted \code{das_} object will not have the format required by subsequent +#' swfscDAS functions, and thus it is safest to drop the \code{das_} class. If a +#' data frame is passed to downstream \code{swfscDAS} functions that require a +#' \code{das_} object, then they will attempt to coerce the object to the +#' necessary \code{das_} class See \code{\link{as_das_dfr}} and +#' \code{\link{as_das_df}} for more details. #' #' @name subsetting #' #' @examples -#' y <- system.file("das_sample.das", package = "swfscDAS") +#' y <- system.file("extdata", "das_sample.das", package = "swfscDAS") #' y.read <- das_read(y) #' #' # All return a data frame: diff --git a/R/swfscDAS-package.R b/R/swfscDAS-package.R index 2836a95..bfbc33d 100644 --- a/R/swfscDAS-package.R +++ b/R/swfscDAS-package.R @@ -19,7 +19,7 @@ #' @importFrom magrittr %>% #' @importFrom methods setOldClass #' @importFrom parallel clusterExport detectCores parLapplyLB stopCluster -#' @importFrom readr cols col_character fwf_positions read_fwf +#' @importFrom readr cols col_character fwf_cols fwf_positions read_fwf #' @importFrom rlang !! .data #' @importFrom purrr map_chr pmap pmap_int pmap_lgl #' @importFrom sf st_as_sf st_cast st_coordinates st_geometry st_intersects diff --git a/inst/Ship_sample.dat b/inst/extdata/Ship_sample.dat similarity index 100% rename from inst/Ship_sample.dat rename to inst/extdata/Ship_sample.dat diff --git a/inst/SpCodes_sample.dat b/inst/extdata/SpCodes_sample.dat similarity index 100% rename from inst/SpCodes_sample.dat rename to inst/extdata/SpCodes_sample.dat diff --git a/inst/das_sample.das b/inst/extdata/das_sample.das similarity index 100% rename from inst/das_sample.das rename to inst/extdata/das_sample.das diff --git a/inst/das_sample_randpicks.csv b/inst/extdata/das_sample_randpicks.csv similarity index 100% rename from inst/das_sample_randpicks.csv rename to inst/extdata/das_sample_randpicks.csv diff --git a/inst/das_sample_stratum.csv b/inst/extdata/das_sample_stratum.csv similarity index 100% rename from inst/das_sample_stratum.csv rename to inst/extdata/das_sample_stratum.csv diff --git a/man/as_das_df.Rd b/man/as_das_df.Rd index 55b8642..62d6379 100644 --- a/man/as_das_df.Rd +++ b/man/as_das_df.Rd @@ -16,16 +16,16 @@ as_das_df(x) \item{x}{an object to be coerced to class \code{das_df}} } \value{ -An object of class `das_df` +An object of class \code{das_df} } \description{ Check if an object is of class \code{das_df}, or coerce it if possible. } \details{ Only data frames can be coerced to an object of class \code{das_df}. - If \code{x} does not have column names and classes as specified in \code{\link{das_df-class}}, - then the function returns an error message detailing the first column that does not - meet the requirements of a \code{das_df} object. +If \code{x} does not have column names and classes as specified in \code{\link{das_df-class}}, +then the function returns an error message detailing the first column that does not +meet the requirements of a \code{das_df} object. } \seealso{ \code{\link{das_df-class}} diff --git a/man/as_das_dfr.Rd b/man/as_das_dfr.Rd index 181225d..c7c97ca 100644 --- a/man/as_das_dfr.Rd +++ b/man/as_das_dfr.Rd @@ -16,16 +16,16 @@ as_das_dfr(x) \item{x}{an object to be coerced to class \code{das_dfr}} } \value{ -An object of class `das_dfr` +An object of class \code{das_dfr} } \description{ Check if an object is of class \code{das_dfr}, or coerce it if possible. } \details{ Only data frames can be coerced to an object of class \code{das_dfr}. - If \code{x} does not have column names and classes as specified in \code{\link{das_dfr-class}}, - then the function returns an error message detailing the first column that does not - meet the requirements of a \code{das_dfr} object. +If \code{x} does not have column names and classes as specified in \code{\link{das_dfr-class}}, +then the function returns an error message detailing the first column that does not +meet the requirements of a \code{das_dfr} object. } \seealso{ \code{\link{das_dfr-class}} diff --git a/man/das_check.Rd b/man/das_check.Rd index fe0b67a..bd81b62 100644 --- a/man/das_check.Rd +++ b/man/das_check.Rd @@ -8,7 +8,8 @@ das_check( file, skip = 0, file.out = NULL, - sp.codes = NULL, + sp.codes.file = NULL, + sp.codes.skip = 0, print.cruise.nums = TRUE ) } @@ -20,9 +21,13 @@ das_check( \item{file.out}{filename to which to write the error log; default is \code{NULL}} -\item{sp.codes}{character; filename of .dat file from which to read -accepted species codes. If \code{NULL}, species codes will not be checked. -Default is \code{NULL}} +\item{sp.codes.file}{character; default is \code{NULL}. +Filename of the SpCodes file from which to read the species codes. +If \code{NULL}, the default (internal) file will be used. +The SpCodes file will be read by \code{\link[=das_spcodes_read]{das_spcodes_read()}}} + +\item{sp.codes.skip}{integer; default is 0. +Passed directly to \code{skip} argument of \code{\link[=das_spcodes_read]{das_spcodes_read()}}} \item{print.cruise.nums}{logical; indicates if a table with all the cruise numbers in the \code{x} should be printed using @@ -44,71 +49,71 @@ Check that DAS file has accepted formatting and values Precursor to a more comprehensive DASCHECK program. This function checks that the following is true: \itemize{ - \item Event codes are one of the following: #, *, ?, 1, 2, 3, 4, 5, 6, 7, 8, - A, B, C, E, F, k, K, N, P, Q, r, R, s, S, t, V, W, g, G, p, X, Y, Z - \item Latitude values are between -90 and 90 (inclusive; NA values are ignored) - \item Longitude values are between -180 and 180 (inclusive; NA values are ignored) - \item The effort dot matches effort determined using B, R, and E events - \item There are an equal number of R and E events, and they alternate occurrences - \item A BR event series or R event does not occur while already on effort - \item An E event does not occur while already off effort - \item All Data# columns for non-C events are right-justified - \item Only C events have data past the 99th column in the DAS file - \item The following events have NA (blank) Data# columns: * - \item All of *, B, R, E, V, W, N, P, and Q events have NA Data# columns - where specified (see format pdf for more details) - \item Event/column pairs meet the following requirements: +\item Event codes are one of the following: #, *, ?, 1, 2, 3, 4, 5, 6, 7, 8, +A, B, C, E, F, k, K, N, P, Q, r, R, s, S, t, V, W, g, G, p, X, Y, Z +\item Latitude values are between -90 and 90 (inclusive; NA values are ignored) +\item Longitude values are between -180 and 180 (inclusive; NA values are ignored) +\item The effort dot matches effort determined using B, R, and E events +\item There are an equal number of R and E events, and they alternate occurrences +\item A BR event series or R event does not occur while already on effort +\item An E event does not occur while already off effort +\item All Data# columns for non-C events are right-justified +\item Only C events have data past the 99th column in the DAS file +\item The following events have NA (blank) Data# columns: * +\item All of *, B, R, E, V, W, N, P, and Q events have NA Data# columns +where specified (see format pdf for more details) +\item Event/column pairs meet the following requirements: } \tabular{llll}{ - \emph{Item} \tab \emph{Event} \tab \emph{Column} \tab \emph{Requirement} \cr - Cruise number \tab B \tab Data1 \tab Can be converted to a numeric value \cr - Mode \tab B \tab Data2 \tab Must be one of C, P, c, p, or NA (blank) \cr - Echo sounder \tab B \tab Data4 \tab Must be one of Y, N, y, n, or NA (blank) \cr - Effort type \tab R \tab Data1 \tab Must be one of F, N, S, or NA (blank) \cr - ESW sides \tab R \tab Data2 \tab Effective strip width; must be one of F, H, or NA (blank) \cr - Course \tab N \tab Data1 \tab Can be converted to a numeric value \cr - Speed \tab N \tab Data2 \tab Can be converted to a numeric value \cr - Beaufort \tab V \tab Data1 \tab Must be a whole number between 0 and 9 \cr - Swell height \tab V \tab Data2 \tab Can be converted to a numeric value \cr - Wind speed \tab V \tab Data5 \tab Can be converted to a numeric value \cr - Rain or fog \tab W \tab Data1 \tab Must be between 0 and 5 and either a whole number or have decimal value .5\cr - Horizontal sun \tab W \tab Data2 \tab Must be a whole number between 0 and 12 \cr - Vertical sun \tab W \tab Data3 \tab Must be a whole number between 0 and 12 \cr - Visibility \tab W \tab Data5 \tab Can be converted to a numeric value \cr - Sighting (mammal) \tab S, K, M \tab Data3-7 \tab Can be converted to a numeric value \cr - Sighting (mammal) \tab G \tab Data5-7 \tab Can be converted to a numeric value \cr - Sighting cue (mammal) \tab S, K, M \tab Data3 \tab Must be a whole number between 1 and 6 \cr - Sighting method (mammal) \tab S, K, M, G \tab Data4 \tab Must be a whole number between 1 and 7 \cr - Bearing (mammal) \tab S, K, M, G \tab Data5 \tab Must be a whole number between 0 and 360 \cr - Photos \tab A \tab Data3 \tab Must be one of N, Y, n, y, or NA (blank) \cr - Birds \tab A \tab Data4 \tab Must be one of N, Y, n, y, or NA (blank) \cr - Calibration school \tab S, K, M \tab Data10 \tab Must be one of N, Y, n, y, or NA (blank) \cr - Aerial photos taken \tab S, K, M \tab Data11 \tab Must be one of N, Y, n, y, or NA (blank) \cr - Biopsy taken \tab S, K, M \tab Data12 \tab Must be one of N, Y, n, y, or NA (blank) \cr - Species codes \tab A \tab Data5-8 \tab If a species codes file is provided, must be one of the provided codes \cr - Resight \tab s, k \tab Data2-5 \tab Can be converted to a numeric value \cr - Turtle species \tab t \tab Data2 \tab If a species codes file is provided, must be one of the provided codes \cr - Turtle sighting \tab t \tab Data3-5, 7 \tab Can be converted to a numeric value \cr - Turtle JFR \tab t \tab Data6 \tab Must be one of F, J, N, R, or NA (blank) \cr - Fishing vessel \tab F \tab Data2-4 \tab Can be converted to a numeric value \cr - Sighting info \tab 1-8 \tab Data2-8 \tab Can be converted to a numeric value \cr - Sighting info \tab 1-8 \tab Data9 \tab The Data9 column must be NA (blank) for events 1-8 +\emph{Item} \tab \emph{Event} \tab \emph{Column} \tab \emph{Requirement} \cr +Cruise number \tab B \tab Data1 \tab Can be converted to a numeric value \cr +Mode \tab B \tab Data2 \tab Must be one of C, P, c, p, or NA (blank) \cr +Echo sounder \tab B \tab Data4 \tab Must be one of Y, N, y, n, or NA (blank) \cr +Effort type \tab R \tab Data1 \tab Must be one of F, N, S, or NA (blank) \cr +ESW sides \tab R \tab Data2 \tab Effective strip width; must be one of F, H, or NA (blank) \cr +Course \tab N \tab Data1 \tab Can be converted to a numeric value \cr +Speed \tab N \tab Data2 \tab Can be converted to a numeric value \cr +Beaufort \tab V \tab Data1 \tab Must be a whole number between 0 and 9 \cr +Swell height \tab V \tab Data2 \tab Can be converted to a numeric value \cr +Wind speed \tab V \tab Data5 \tab Can be converted to a numeric value \cr +Rain or fog \tab W \tab Data1 \tab Must be between 0 and 5 and either a whole number or have decimal value .5\cr +Horizontal sun \tab W \tab Data2 \tab Must be a whole number between 0 and 12 \cr +Vertical sun \tab W \tab Data3 \tab Must be a whole number between 0 and 12 \cr +Visibility \tab W \tab Data5 \tab Can be converted to a numeric value \cr +Sighting (mammal) \tab S, K, M \tab Data3-7 \tab Can be converted to a numeric value \cr +Sighting (mammal) \tab G \tab Data5-7 \tab Can be converted to a numeric value \cr +Sighting cue (mammal) \tab S, K, M \tab Data3 \tab Must be a whole number between 1 and 6 \cr +Sighting method (mammal) \tab S, K, M, G \tab Data4 \tab Must be a whole number between 1 and 7 \cr +Bearing (mammal) \tab S, K, M, G \tab Data5 \tab Must be a whole number between 0 and 360 \cr +Photos \tab A \tab Data3 \tab Must be one of N, Y, n, y, or NA (blank) \cr +Birds \tab A \tab Data4 \tab Must be one of N, Y, n, y, or NA (blank) \cr +Calibration school \tab S, K, M \tab Data10 \tab Must be one of N, Y, n, y, or NA (blank) \cr +Aerial photos taken \tab S, K, M \tab Data11 \tab Must be one of N, Y, n, y, or NA (blank) \cr +Biopsy taken \tab S, K, M \tab Data12 \tab Must be one of N, Y, n, y, or NA (blank) \cr +Species codes \tab A \tab Data5-8 \tab If a species codes file is provided, must be one of the provided codes \cr +Resight \tab s, k \tab Data2-5 \tab Can be converted to a numeric value \cr +Turtle species \tab t \tab Data2 \tab If a species codes file is provided, must be one of the provided codes \cr +Turtle sighting \tab t \tab Data3-5, 7 \tab Can be converted to a numeric value \cr +Turtle JFR \tab t \tab Data6 \tab Must be one of F, J, N, R, or NA (blank) \cr +Fishing vessel \tab F \tab Data2-4 \tab Can be converted to a numeric value \cr +Sighting info \tab 1-8 \tab Data2-8 \tab Can be converted to a numeric value \cr +Sighting info \tab 1-8 \tab Data9 \tab The Data9 column must be NA (blank) for events 1-8 } In the table above, 'between' means inclusive. Long-term items, and checks that are not performed: \itemize{ - \item Check that datetimes are sequential, meaning they - 1) are the same as or 2) come after the previous event - \item Check that A events only come immediately after a G/S/K/M event, - and all G/S/K/M events have an A after them. - And that each has at least one group size estimate (1:8 event) +\item Check that datetimes are sequential, meaning they +1) are the same as or 2) come after the previous event +\item Check that A events only come immediately after a G/S/K/M event, +and all G/S/K/M events have an A after them. +And that each has at least one group size estimate (1:8 event) } } \examples{ -y <- system.file("das_sample.das", package = "swfscDAS") +y <- system.file("extdata", "das_sample.das", package = "swfscDAS") if (interactive()) das_check(y) } diff --git a/man/das_chop_condition.Rd b/man/das_chop_condition.Rd index e7ce3f1..7e51426 100644 --- a/man/das_chop_condition.Rd +++ b/man/das_chop_condition.Rd @@ -41,9 +41,9 @@ Default is \code{NULL} since these distances should have already been calculated \value{ List of two data frames: \itemize{ - \item \code{x}, with columns added for the corresponding unique segment code and number - \item segdata: data frame with one row for each segment, and columns with - relevant data (see \code{\link{das_effort}} for specifics) +\item \code{x}, with columns added for the corresponding unique segment code and number +\item segdata: data frame with one row for each segment, and columns with +relevant data (see \code{\link{das_effort}} for specifics) } } \description{ @@ -51,51 +51,51 @@ Chop DAS data into a new effort segment every time a specified condition changes } \details{ WARNING - do not call this function directly! - It is exported for documentation purposes, but is intended for internal package use only. +It is exported for documentation purposes, but is intended for internal package use only. - This function is intended to be called by \code{\link{das_effort}} - when the "condition" method is specified. - Thus, \code{x} must be filtered for events (rows) where either - the 'OnEffort' column is \code{TRUE} or the 'Event' column is "E"; - see \code{\link{das_effort}} for more details. - This function chops each continuous effort section (henceforth 'effort sections') - in \code{x} into modeling segments (henceforth 'segments') by - creating a new segment every time a specified condition changes. - Each effort section runs from an "R" event to its corresponding "E" event. - After chopping, \code{\link{das_segdata}} is called - (with \code{segdata.method = "maxdist"}) - to get relevant segdata information for each segment. +This function is intended to be called by \code{\link{das_effort}} +when the "condition" method is specified. +Thus, \code{x} must be filtered for events (rows) where either +the 'OnEffort' column is \code{TRUE} or the 'Event' column is "E"; +see \code{\link{das_effort}} for more details. +This function chops each continuous effort section (henceforth 'effort sections') +in \code{x} into modeling segments (henceforth 'segments') by +creating a new segment every time a specified condition changes. +Each effort section runs from an "R" event to its corresponding "E" event. +After chopping, \code{\link{das_segdata}} is called +(with \code{segdata.method = "maxdist"}) +to get relevant segdata information for each segment. - Changes in the one of the conditions specified in the \code{conditions} - argument triggers a new segment. - One exception is if the event at which this condition change occurs is part of an event series, - meaning one of several events in a row at the same lat/lon points (such as a PVNW event series). - In this situation, the final event of the event series is considered the last event - of the current effort segment, and thus also the start of the next effort segment. +Changes in the one of the conditions specified in the \code{conditions} +argument triggers a new segment. +One exception is if the event at which this condition change occurs is part of an event series, +meaning one of several events in a row at the same lat/lon points (such as a PVNW event series). +In this situation, the final event of the event series is considered the last event +of the current effort segment, and thus also the start of the next effort segment. - Related, when multiple condition changes happen at the same lat/lon points, - such as a "RPVNW" series of events at the beginning of the effort section. - When this happens, no segments of length zero are created; - rather, a single segment is created that includes all of the condition changes - (i.e. all of the events in the event series) that happened during - the series of events (i.e. at the same location). - Note that this combining of events at the same position happens - even if \code{seg.min.km = 0}. +Related, when multiple condition changes happen at the same lat/lon points, +such as a "RPVNW" series of events at the beginning of the effort section. +When this happens, no segments of length zero are created; +rather, a single segment is created that includes all of the condition changes +(i.e. all of the events in the event series) that happened during +the series of events (i.e. at the same location). +Note that this combining of events at the same position happens +even if \code{seg.min.km = 0}. - In addition, (almost) all segments whose length is less than \code{seg.min.km} - are combined with the segment immediately following them to ensure that the length - of (almost) all segments is at least \code{seg.min.km}. - This allows users to account for situations where multiple conditions, - such as Beaufort and the visibility, change in rapid succession, for instance <0.1 km apart. - When segments are combined, a message is printed, and the condition that was - recorded for the maximum distance within the new segment is reported. - See \code{\link{das_segdata}}, \code{segdata.method = "maxdist"}, for more details - about how the segdata information is determined. - The only exception to this rule is if the short segment ends in an "E" event, - meaning it is the last segment of the effort section. - Since in this case there is no 'next' segment, - this short segment is left as-is. +In addition, (almost) all segments whose length is less than \code{seg.min.km} +are combined with the segment immediately following them to ensure that the length +of (almost) all segments is at least \code{seg.min.km}. +This allows users to account for situations where multiple conditions, +such as Beaufort and the visibility, change in rapid succession, for instance <0.1 km apart. +When segments are combined, a message is printed, and the condition that was +recorded for the maximum distance within the new segment is reported. +See \code{\link{das_segdata}}, \code{segdata.method = "maxdist"}, for more details +about how the segdata information is determined. +The only exception to this rule is if the short segment ends in an "E" event, +meaning it is the last segment of the effort section. +Since in this case there is no 'next' segment, +this short segment is left as-is. - If the column \code{dist_from_prev} does not exist, the distance between - subsequent events is calculated as described in \code{\link{das_effort}} +If the column \code{dist_from_prev} does not exist, the distance between +subsequent events is calculated as described in \code{\link{das_effort}} } diff --git a/man/das_chop_equallength.Rd b/man/das_chop_equallength.Rd index 7afa0fc..e7c3dd9 100644 --- a/man/das_chop_equallength.Rd +++ b/man/das_chop_equallength.Rd @@ -45,11 +45,11 @@ frame, randpicks values will be extracted from the data frame. If \value{ List of three data frames: \itemize{ - \item \code{x}, with columns added for the corresponding unique segment - code and number \item segdata: data frame with one row for each segment, - and columns with relevant data (see \code{\link{das_effort}} for specifics) - \item randpicks: data frame with record of length allocations (see Details - section above) +\item \code{x}, with columns added for the corresponding unique segment +code and number \item segdata: data frame with one row for each segment, +and columns with relevant data (see \code{\link{das_effort}} for specifics) +\item randpicks: data frame with record of length allocations (see Details +section above) } } \description{ @@ -58,64 +58,64 @@ conditions by segment } \details{ WARNING - do not call this function directly! It is exported for - documentation purposes, but is intended for internal package use only. +documentation purposes, but is intended for internal package use only. - This function is intended to be called by \code{\link{das_effort}} when the - "equallength" method is specified. Thus, \code{x} must be filtered for - events (rows) where either the 'OnEffort' column is \code{TRUE} or the - 'Event' column is "E"; see \code{\link{das_effort}} for more details. This - function chops each continuous effort section (henceforth 'effort - sections') in \code{x} into modeling segments (henceforth 'segments') of - equal length. Each effort section runs from an "R" event to its - corresponding "E" event. After chopping, \code{\link{das_segdata}} is - called to get relevant segdata information for each segment. +This function is intended to be called by \code{\link{das_effort}} when the +"equallength" method is specified. Thus, \code{x} must be filtered for +events (rows) where either the 'OnEffort' column is \code{TRUE} or the +'Event' column is "E"; see \code{\link{das_effort}} for more details. This +function chops each continuous effort section (henceforth 'effort +sections') in \code{x} into modeling segments (henceforth 'segments') of +equal length. Each effort section runs from an "R" event to its +corresponding "E" event. After chopping, \code{\link{das_segdata}} is +called to get relevant segdata information for each segment. - When chopping the effort sections in segments of length \code{seg.km}, - there are several possible scenarios: - \itemize{ - \item The extra length remaining after chopping is greater than or equal - to half of the target segment length (i.e. \code{>= 0.5*seg.km}): the - extra length is assigned to a random portion of the effort section as its - own segment - (\href{https://github.com/swfsc/swfscDAS/blob/master/inst/DAS_chop_equallength_figures.pdf}{see - Fig. 1a}) \item The extra length remaining after chopping is less than - half of the target segment length (i.e. \code{< 0.5*seg.km}): the extra - length is added to one of the (randomly selected) equal-length segments - (\href{https://github.com/swfsc/swfscDAS/blob/master/inst/DAS_chop_equallength_figures.pdf}{see - Fig. 1b}) \item The length of the effort section is less than or equal to - the target segment length: the entire segment becomes a segment - (\href{https://github.com/swfsc/swfscDAS/blob/master/inst/DAS_chop_equallength_figures.pdf}{see - Fig. 1c}) \item The length of the effort section is zero: a segment of - length zero. If there are more than two events (the "B"/R" and "E" - events), the function throws a warning - } +When chopping the effort sections in segments of length \code{seg.km}, +there are several possible scenarios: +\itemize{ +\item The extra length remaining after chopping is greater than or equal +to half of the target segment length (i.e. \code{>= 0.5*seg.km}): the +extra length is assigned to a random portion of the effort section as its +own segment +(\href{https://github.com/swfsc/swfscDAS/blob/master/inst/DAS_chop_equallength_figures.pdf}{see +Fig. 1a}) \item The extra length remaining after chopping is less than +half of the target segment length (i.e. \code{< 0.5*seg.km}): the extra +length is added to one of the (randomly selected) equal-length segments +(\href{https://github.com/swfsc/swfscDAS/blob/master/inst/DAS_chop_equallength_figures.pdf}{see +Fig. 1b}) \item The length of the effort section is less than or equal to +the target segment length: the entire segment becomes a segment +(\href{https://github.com/swfsc/swfscDAS/blob/master/inst/DAS_chop_equallength_figures.pdf}{see +Fig. 1c}) \item The length of the effort section is zero: a segment of +length zero. If there are more than two events (the "B"/R" and "E" +events), the function throws a warning +} - Therefore, the length of each segment is constrained to be between one half - and one and one half of \code{seg.km} (i.e. \code{0.5*seg.km <=} segment - length \code{>=1.5*seg.km}), and the central tendency is approximately - equal to the target segment length. The only exception is when a continuous - effort section is less than one half of the target segment length (i.e. - \code{< 0.5*seg.km}; - \href{https://github.com/swfsc/swfscDAS/blob/master/inst/DAS_chop_equallength_figures.pdf}{see - Fig. 1c}). +Therefore, the length of each segment is constrained to be between one half +and one and one half of \code{seg.km} (i.e. \code{0.5*seg.km <=} segment +length \code{>=1.5*seg.km}), and the central tendency is approximately +equal to the target segment length. The only exception is when a continuous +effort section is less than one half of the target segment length (i.e. +\code{< 0.5*seg.km}; +\href{https://github.com/swfsc/swfscDAS/blob/master/inst/DAS_chop_equallength_figures.pdf}{see +Fig. 1c}). - Note the PDF with Figs. 1a - 1c is included in the package, and can be - found at: \code{system.file("DAS_chop_equal_figures.pdf", package = +Note the PDF with Figs. 1a - 1c is included in the package, and can be +found at: \code{system.file("DAS_chop_equal_figures.pdf", package = "swfscDAS")} - 'Randpicks' is a record of the random assignments that were made when - chopping the effort sections into segments, and can be saved to allow users - to recreate the same random allocation of extra km when chopping. The - randpicks returned by this function is a data frame with two columns: the - number of the effort section and the randpick value. Users should save the - randpicks output to a CSV file, which then can be specified using the - \code{randpicks.load} argument to recreate the same effort segments from - \code{x} (i.e., using the same DAS data) in the future. Note that when - saving with \code{\link[utils:read.table]{write.csv}}, users must specify - \code{row.names = FALSE} so that the CSV file only has two columns. For an - example randpicks file, see \code{system.file("das_sample_randpicks.csv", - package = "swfscDAS")} +'Randpicks' is a record of the random assignments that were made when +chopping the effort sections into segments, and can be saved to allow users +to recreate the same random allocation of extra km when chopping. The +randpicks returned by this function is a data frame with two columns: the +number of the effort section and the randpick value. Users should save the +randpicks output to a CSV file, which then can be specified using the +\code{randpicks.load} argument to recreate the same effort segments from +\code{x} (i.e., using the same DAS data) in the future. Note that when +saving with \code{\link[utils:read.table]{write.csv}}, users must specify +\code{row.names = FALSE} so that the CSV file only has two columns. For an +example randpicks file, see +\code{system.file("extdata", "das_sample_randpicks.csv", package = "swfscDAS")} - If the column \code{dist_from_prev} does not exist, the distance between - subsequent events is calculated as described in \code{\link{das_effort}} +If the column \code{dist_from_prev} does not exist, the distance between +subsequent events is calculated as described in \code{\link{das_effort}} } diff --git a/man/das_chop_section.Rd b/man/das_chop_section.Rd index fb6b2e7..28ffddc 100644 --- a/man/das_chop_section.Rd +++ b/man/das_chop_section.Rd @@ -28,25 +28,25 @@ Default is \code{NULL} since these distances should have already been calculated \item{num.cores}{see \code{\link{das_effort}}} } \value{ -See \code{\link{das_chop_equallength}}. The randpicks values will all be \code{NA} +See \code{\link[=das_chop_equallength]{das_chop_equallength()}}. The randpicks values will all be \code{NA} } \description{ Chop DAS data into effort segments by continuous effort section } \details{ WARNING - do not call this function directly! - It is exported for documentation purposes, but is intended for internal package use only. +It is exported for documentation purposes, but is intended for internal package use only. - This function is simply a wrapper for \code{\link{das_chop_equallength}}. - It calls \code{\link{das_chop_equallength}}, with \code{seg.km} set to a - value larger than the longest continuous effort section in \code{x}. - Thus, the effort is 'chopped' into the continuous effort sections and then summarized. +This function is simply a wrapper for \code{\link{das_chop_equallength}}. +It calls \code{\link{das_chop_equallength}}, with \code{seg.km} set to a +value larger than the longest continuous effort section in \code{x}. +Thus, the effort is 'chopped' into the continuous effort sections and then summarized. - See the Examples section for an example where the two methods give the same output. - Note that the longest continuous effort section in the sample data is ~22km. +See the Examples section for an example where the two methods give the same output. +Note that the longest continuous effort section in the sample data is ~22km. } \examples{ -y <- system.file("das_sample.das", package = "swfscDAS") +y <- system.file("extdata", "das_sample.das", package = "swfscDAS") y.proc <- das_process(y) y.eff1 <- das_effort(y.proc, method = "equallength", seg.km = 25, num.cores = 1) diff --git a/man/das_comments.Rd b/man/das_comments.Rd index ae06f89..a948476 100644 --- a/man/das_comments.Rd +++ b/man/das_comments.Rd @@ -21,18 +21,18 @@ or a data frame that can be coerced to a \code{das_dfr} object} } \value{ \code{x}, filtered for C events and with the added column - comment_str containing the concatenated comment strings +comment_str containing the concatenated comment strings } \description{ Extract comments from DAS data } \details{ This function recreates the comment strings by - pasting the Data# columns back together for the C events (comments). - See the examples section for how to search for comments with certain phrases +pasting the Data# columns back together for the C events (comments). +See the examples section for how to search for comments with certain phrases } \examples{ -y <- system.file("das_sample.das", package = "swfscDAS") +y <- system.file("extdata", "das_sample.das", package = "swfscDAS") y.proc <- das_process(y) das_comments(y.proc) diff --git a/man/das_df-class.Rd b/man/das_df-class.Rd index cf3ef1d..14d06aa 100644 --- a/man/das_df-class.Rd +++ b/man/das_df-class.Rd @@ -6,66 +6,66 @@ \title{\code{das_df} class} \description{ The \code{das_df} class is a subclass of \code{\link[base]{data.frame}}, - created to provide a concise and robust way to ensure that the input to downstream DAS processing functions, - such as \code{\link{das_sight}}, adheres to certain requirements. - Specifically, objects of class \code{das_df} are data frames with specific column names and classes, - as detailed in the 'Properties of \code{das_df}' section. Objects of class \code{das_df} are created by - \code{\link{das_process}} or \code{\link{as_das_df}}, and are intended to be passed directly to - DAS processing functions such as \code{\link{das_sight}}. +created to provide a concise and robust way to ensure that the input to downstream DAS processing functions, +such as \code{\link{das_sight}}, adheres to certain requirements. +Specifically, objects of class \code{das_df} are data frames with specific column names and classes, +as detailed in the 'Properties of \code{das_df}' section. Objects of class \code{das_df} are created by +\code{\link{das_process}} or \code{\link{as_das_df}}, and are intended to be passed directly to +DAS processing functions such as \code{\link{das_sight}}. - Subsetting, say for a specific date or cruise number, or otherwise altering an object of class \code{das_df} - will cause the object to drop its \code{das_df} class attribute. - If this object is then passed to a DAS processing function such as \code{\link{das_sight}}, the function - will try to coerce the object to a \code{das_df} object. +Subsetting, say for a specific date or cruise number, or otherwise altering an object of class \code{das_df} +will cause the object to drop its \code{das_df} class attribute. +If this object is then passed to a DAS processing function such as \code{\link{das_sight}}, the function +will try to coerce the object to a \code{das_df} object. } \section{Properties of \code{das_df} objects}{ - All values in the Event column must not be \code{NA}. +All values in the Event column must not be \code{NA}. - Objects of class \code{das_df} have a class attribute of \code{c("das_df", "data.frame")}. - In addition, they must have the following column names and classes: - \tabular{ll}{ - \emph{Column name} \tab \emph{Column class}\cr - Event \tab "character"\cr - DateTime \tab c("POSIXct", "POSIXt")\cr - Lat \tab "numeric"\cr - Lon \tab "numeric"\cr - OnEffort \tab "logical"\cr - Cruise \tab "numeric"\cr - Mode \tab "character"\cr - EffType \tab "character"\cr - Course \tab "numeric"\cr - SpdKt \tab "numeric"\cr - Bft \tab "numeric"\cr - SwellHght \tab "numeric"\cr - WindSpdKt \tab "numeric"\cr - RainFog \tab "numeric"\cr - HorizSun \tab "numeric"\cr - VertSun \tab "numeric"\cr - Glare \tab "logical"\cr - Vis \tab "numeric"\cr - ObsL \tab "character"\cr - Rec \tab "character"\cr - ObsR \tab "character"\cr - ObsInd \tab "character"\cr - Data1 \tab "character"\cr - Data2 \tab "character"\cr - Data3 \tab "character"\cr - Data4 \tab "character"\cr - Data5 \tab "character"\cr - Data6 \tab "character"\cr - Data7 \tab "character"\cr - Data8 \tab "character"\cr - Data9 \tab "character"\cr - Data10 \tab "character"\cr - Data11 \tab "character"\cr - Data12 \tab "character"\cr - EffortDot \tab "logical"\cr - EventNum \tab "integer"\cr - file_das \tab "character"\cr - line_num \tab "integer"\cr - } +Objects of class \code{das_df} have a class attribute of \code{c("das_df", "data.frame")}. +In addition, they must have the following column names and classes: +\tabular{ll}{ +\emph{Column name} \tab \emph{Column class}\cr +Event \tab "character"\cr +DateTime \tab c("POSIXct", "POSIXt")\cr +Lat \tab "numeric"\cr +Lon \tab "numeric"\cr +OnEffort \tab "logical"\cr +Cruise \tab "numeric"\cr +Mode \tab "character"\cr +EffType \tab "character"\cr +Course \tab "numeric"\cr +SpdKt \tab "numeric"\cr +Bft \tab "numeric"\cr +SwellHght \tab "numeric"\cr +WindSpdKt \tab "numeric"\cr +RainFog \tab "numeric"\cr +HorizSun \tab "numeric"\cr +VertSun \tab "numeric"\cr +Glare \tab "logical"\cr +Vis \tab "numeric"\cr +ObsL \tab "character"\cr +Rec \tab "character"\cr +ObsR \tab "character"\cr +ObsInd \tab "character"\cr +Data1 \tab "character"\cr +Data2 \tab "character"\cr +Data3 \tab "character"\cr +Data4 \tab "character"\cr +Data5 \tab "character"\cr +Data6 \tab "character"\cr +Data7 \tab "character"\cr +Data8 \tab "character"\cr +Data9 \tab "character"\cr +Data10 \tab "character"\cr +Data11 \tab "character"\cr +Data12 \tab "character"\cr +EffortDot \tab "logical"\cr +EventNum \tab "integer"\cr +file_das \tab "character"\cr +line_num \tab "integer"\cr +} } \seealso{ diff --git a/man/das_dfr-class.Rd b/man/das_dfr-class.Rd index 021ef41..483528b 100644 --- a/man/das_dfr-class.Rd +++ b/man/das_dfr-class.Rd @@ -6,46 +6,46 @@ \title{\code{das_dfr} class} \description{ The \code{das_dfr} class is a subclass of \code{\link[base]{data.frame}}, - created to provide a concise and robust way to ensure that the input to \code{\link{das_process}} - adheres to certain requirements. - Specifically, objects of class \code{das_dfr} are data frames with specific column names and classes, - as detailed in the 'Properties of \code{das_dfr}' section. Objects of class \code{das_dfr} are created by - \code{\link{das_read}} or \code{\link{as_das_dfr}}, and are intended to be passed directly to - \code{\link{das_process}}. +created to provide a concise and robust way to ensure that the input to \code{\link{das_process}} +adheres to certain requirements. +Specifically, objects of class \code{das_dfr} are data frames with specific column names and classes, +as detailed in the 'Properties of \code{das_dfr}' section. Objects of class \code{das_dfr} are created by +\code{\link{das_read}} or \code{\link{as_das_dfr}}, and are intended to be passed directly to +\code{\link{das_process}}. - Subsetting or otherwise altering an object of class \code{das_dfr} will cause the object to drop its - \code{das_dfr} class attribute. \code{\link{das_process}} will then try to coerce the object to a - \code{das_dfr} object. It is \bold{strongly} recommended to pass an object of class \code{das_dfr} to - \code{\link{das_process}} before subsetting, e.g. for events from a certain date range. +Subsetting or otherwise altering an object of class \code{das_dfr} will cause the object to drop its +\code{das_dfr} class attribute. \code{\link{das_process}} will then try to coerce the object to a +\code{das_dfr} object. It is \bold{strongly} recommended to pass an object of class \code{das_dfr} to +\code{\link{das_process}} before subsetting, e.g. for events from a certain date range. } \section{Properties of \code{das_dfr} objects}{ - Objects of class \code{das_dfr} have a class attribute of \code{c("das_dfr", "data.frame")}. - In addition, they must have the following column names and classes: - \tabular{ll}{ - \emph{Column name} \tab \emph{Column class}\cr - Event \tab "character"\cr - EffortDot \tab "logical"\cr - DateTime \tab c("POSIXct", "POSIXt")\cr - Lat \tab "numeric"\cr - Lon \tab "numeric"\cr - Data1 \tab "character"\cr - Data2 \tab "character"\cr - Data3 \tab "character"\cr - Data4 \tab "character"\cr - Data5 \tab "character"\cr - Data6 \tab "character"\cr - Data7 \tab "character"\cr - Data8 \tab "character"\cr - Data9 \tab "character"\cr - Data10 \tab "character"\cr - Data11 \tab "character"\cr - Data12 \tab "character"\cr - EventNum \tab "integer"\cr - file_das \tab "character"\cr - line_num \tab "integer"\cr - } +Objects of class \code{das_dfr} have a class attribute of \code{c("das_dfr", "data.frame")}. +In addition, they must have the following column names and classes: +\tabular{ll}{ +\emph{Column name} \tab \emph{Column class}\cr +Event \tab "character"\cr +EffortDot \tab "logical"\cr +DateTime \tab c("POSIXct", "POSIXt")\cr +Lat \tab "numeric"\cr +Lon \tab "numeric"\cr +Data1 \tab "character"\cr +Data2 \tab "character"\cr +Data3 \tab "character"\cr +Data4 \tab "character"\cr +Data5 \tab "character"\cr +Data6 \tab "character"\cr +Data7 \tab "character"\cr +Data8 \tab "character"\cr +Data9 \tab "character"\cr +Data10 \tab "character"\cr +Data11 \tab "character"\cr +Data12 \tab "character"\cr +EventNum \tab "integer"\cr +file_das \tab "character"\cr +line_num \tab "integer"\cr +} } \seealso{ diff --git a/man/das_effort.Rd b/man/das_effort.Rd index 32a7090..4df4240 100644 --- a/man/das_effort.Rd +++ b/man/das_effort.Rd @@ -37,7 +37,7 @@ Can be "condition", "equallength", "section", or any partial match thereof \item{conditions}{character vector of names of conditions to include in segdata output. These values must be column names from the output of \code{\link{das_process}}, e.g. 'Bft', 'SwellHght', etc. If \code{method == -"condition"}, then these also are the conditions which trigger segment + "condition"}, then these also are the conditions which trigger segment chopping when they change. Only the following conditions can be used for chopping: 'Bft', 'SwellHght', 'RainFog', 'HorizSun', 'VertSun', 'Glare', 'Vis', 'Course', 'SpdKt'} @@ -72,90 +72,89 @@ be faster for smaller datasets} } \value{ List of three data frames: - \itemize{ - \item segdata: one row for every segment, and columns for information - including unique segment number (segnum), the corresponding effort - section (section_id), the segment index within the corresponding effort - section (section_sub_id), the starting and ending line of the segment in - the DAS file (stlin, endlin), start/end/midpoint coordinates(lat1/lon1, - lat2/lon2, and mlat/mlon, respectively), the start/end/midpoint date/time - of the segment (DateTime1, DateTime2, and mDateTime, respectively; - mDateTime is the average of DateTime1 and DateTime2), segment length - (dist), conditions (e.g. Beaufort), and, if applicable, stratum - (InStratumName). - \item sightinfo: details for all sightings in \code{x}, including: the - unique segment number it is associated with, segment mid points - (lat/lon), the 'included' column described in the 'Details' section, and - the output information described in \code{\link{das_sight}} for - \code{return.format} is "default" - \item randpicks: see \code{\link{das_chop_equallength}}; \code{NULL} if - using "condition" method - } +\itemize{ +\item segdata: one row for every segment, and columns for information +including unique segment number (segnum), the corresponding effort +section (section_id), the segment index within the corresponding effort +section (section_sub_id), the starting and ending line of the segment in +the DAS file (stlin, endlin), start/end/midpoint coordinates(lat1/lon1, +lat2/lon2, and mlat/mlon, respectively), the start/end/midpoint date/time +of the segment (DateTime1, DateTime2, and mDateTime, respectively; +mDateTime is the average of DateTime1 and DateTime2), segment length +(dist), conditions (e.g. Beaufort), and, if applicable, stratum +(InStratumName). +\item sightinfo: details for all sightings in \code{x}, including: the +unique segment number it is associated with, segment mid points +(lat/lon), the 'included' column described in the 'Details' section, and +the output information described in \code{\link{das_sight}} for +\code{return.format} is "default" +\item randpicks: see \code{\link{das_chop_equallength}}; \code{NULL} if +using "condition" method +} } \description{ Chop DAS data into effort segments } \details{ -This is the top-level function for chopping processed DAS data into - modeling segments (henceforth 'segments'), and assigning sightings and - related information (e.g., weather conditions) to each segment. This - function returns data frames with all relevant information for the effort - segments and associated sightings ('segdata' and 'sightinfo', - respectively). Before chopping, the DAS data is filtered for events (rows) - where either the 'OnEffort' column is \code{TRUE} or the 'Event' column - "E". In other words, the data is filtered for continuous effort sections - (henceforth 'effort sections'), where effort sections run from "R" to "E" - events (inclusive), and then passed to the chopping function specified - using \code{method}. Note that while B events immediately preceding an R - are on effort, they are ignored during effort chopping. In addition, all on - effort events (other than ? and numeric events) with \code{NA} DateTime, - Lat, or Lon values are verbosely removed. - - If \code{strata.files} is not \code{NULL}, then the effort lines will be - split by the user-provided stratum (strata). In this case, a column - 'stratum' will be added to the end of the segdata data frame with the - user-provided name of the stratum that the segment was in, or \code{NA} if - the segment was not in any of the strata. If no name was provided for the - stratum in \code{strata.files}, then the value will be "Stratum#", where - "#" is the index of the applicable stratum in \code{strata.files}. While - the user can provide as many strata as they want, these strata can share - boundaries but they cannot overlap. See \code{\link{das_effort_strata}} for - more details. - - The following chopping methods are currently available: "condition", - "equallength", and "section. When using the "condition" method, effort - sections are chopped into segments every time a condition changes, thereby - ensuring that the conditions are consistent across the entire segment. See - \code{\link{das_chop_condition}} for more details about this method, - including arguments that must be passed to it via the argument \code{...} - - The "equallength" method consists of chopping effort sections into - equal-length segments of length \code{seg.km}, and doing a weighted average - of the conditions for the length of that segment. See - \code{\link{das_chop_equallength}} for more details about this method, - including arguments that must be passed to it via the argument \code{...} - - The "section" method involves 'chopping' the effort into continuous effort - sections, i.e. each continuous effort section is a single effort segment. - See \code{\link{das_chop_section}} for more details about this method. - - The distance between the lat/lon points of subsequent events is calculated - using the method specified in \code{distance.method}. If "greatcircle", - \code{\link{distance_greatcircle}} is used, while - \code{\link[swfscMisc]{distance}} is used otherwise. See - \code{\link{das_sight}} for how the sightings are processed. - - The sightinfo data frame includes the column 'included', which is used in - \code{\link{das_effort_sight}} when summarizing the number of sightings and - animals for selected species. \code{\link{das_effort_sight}} is a separate - function to allow users to personalize the included values as desired for - their analysis. By default, i.e. in the output of this function, 'included' - is \code{TRUE} if: the sighting was made when on effort, by a standard - observer (see \code{\link{das_sight}}), and in a Beaufort sea state less - than or equal to five. +This is the top-level function for chopping processed DAS data into modeling +segments (henceforth 'segments'), and assigning sightings and related +information (e.g., weather conditions) to each segment. This function returns +data frames with all relevant information for the effort segments and +associated sightings ('segdata' and 'sightinfo', respectively). Before +chopping, the DAS data is filtered for events (rows) where either the +'OnEffort' column is \code{TRUE} or the 'Event' column "E". In other words, +the data is filtered for continuous effort sections (henceforth 'effort +sections'), where effort sections run from "R" to "E" events (inclusive), and +then passed to the chopping function specified using \code{method}. Note that +while B events immediately preceding an R are on effort, they are ignored +during effort chopping. In addition, all on effort events (other than ? and +numeric events) with \code{NA} DateTime, Lat, or Lon values are verbosely +removed. + +If \code{strata.files} is not \code{NULL}, then the effort lines will be +split by the user-provided stratum (strata). In this case, a column 'stratum' +will be added to the end of the segdata data frame with the user-provided +name of the stratum that the segment was in, or \code{NA} if the segment was +not in any of the strata. If no name was provided for the stratum in +\code{strata.files}, then the value will be "Stratum#", where "#" is the +index of the applicable stratum in \code{strata.files}. While the user can +provide as many strata as they want, these strata can share boundaries but +they cannot overlap. See \code{\link{das_effort_strata}} for more details. + +The following chopping methods are currently available: "condition", +"equallength", and "section. When using the "condition" method, effort +sections are chopped into segments every time a condition changes, thereby +ensuring that the conditions are consistent across the entire segment. See +\code{\link{das_chop_condition}} for more details about this method, +including arguments that must be passed to it via the argument \code{...} + +The "equallength" method consists of chopping effort sections into +equal-length segments of length \code{seg.km}, and doing a weighted average +of the conditions for the length of that segment. See +\code{\link{das_chop_equallength}} for more details about this method, +including arguments that must be passed to it via the argument \code{...} + +The "section" method involves 'chopping' the effort into continuous effort +sections, i.e. each continuous effort section is a single effort segment. See +\code{\link{das_chop_section}} for more details about this method. + +The distance between the lat/lon points of subsequent events is calculated +using the method specified in \code{distance.method}. If "greatcircle", +\code{\link{distance_greatcircle}} is used, while +\code{\link[swfscMisc]{distance}} is used otherwise. See +\code{\link{das_sight}} for how the sightings are processed. + +The sightinfo data frame includes the column 'included', which is used in +\code{\link{das_effort_sight}} when summarizing the number of sightings and +animals for selected species. \code{\link{das_effort_sight}} is a separate +function to allow users to personalize the included values as desired for +their analysis. By default, i.e. in the output of this function, 'included' +is \code{TRUE} if: the sighting was made when on effort, by a standard +observer (see \code{\link{das_sight}}), and in a Beaufort sea state less than +or equal to five. } \examples{ -y <- system.file("das_sample.das", package = "swfscDAS") +y <- system.file("extdata", "das_sample.das", package = "swfscDAS") y.proc <- das_process(y) # Using "condition" method @@ -169,14 +168,14 @@ das_effort(y.proc, method = "section", num.cores = 1) \donttest{ # Using "equallength" method -y.rand <- system.file("das_sample_randpicks.csv", package = "swfscDAS") +y.rand <- system.file("extdata", "das_sample_randpicks.csv", package = "swfscDAS") das_effort( y.proc, method = "equallength", seg.km = 10, randpicks.load = y.rand, num.cores = 1 ) # Using "section" method and chop by strata -stratum.file <- system.file("das_sample_stratum.csv", package = "swfscDAS") +stratum.file <- system.file("extdata", "das_sample_stratum.csv", package = "swfscDAS") das_effort( y.proc, method = "section", strata.files = list(Poly1 = stratum.file), num.cores = 1 @@ -186,6 +185,6 @@ das_effort( } \seealso{ Internal functions called by \code{das_effort}: - \code{\link{das_chop_condition}}, \code{\link{das_chop_equallength}}, - \code{\link{das_chop_section}}, \code{\link{das_segdata}} +\code{\link{das_chop_condition}}, \code{\link{das_chop_equallength}}, +\code{\link{das_chop_section}}, \code{\link{das_segdata}} } diff --git a/man/das_effort_sight.Rd b/man/das_effort_sight.Rd index e189e96..2a9c62e 100644 --- a/man/das_effort_sight.Rd +++ b/man/das_effort_sight.Rd @@ -32,37 +32,39 @@ See Details section for more information} } \value{ A list, identical to \code{x.list} except for - 1) the nSI and ANI columns added to \code{x.list$segdata}, - one each for each element of \code{sp.codes}, and - 2) the 'included' column of \code{x.list$sightinfo}, which has been set as - \code{FALSE} for sightings of species not listed in \code{sp.codes}. - Thus, the 'included' column in the output accurately reflects - the sightings that were included in the effort segment summaries +\enumerate{ +\item the nSI and ANI columns added to \code{x.list$segdata}, +one each for each element of \code{sp.codes}, and +\item the 'included' column of \code{x.list$sightinfo}, which has been set as +\code{FALSE} for sightings of species not listed in \code{sp.codes}. +Thus, the 'included' column in the output accurately reflects +the sightings that were included in the effort segment summaries +} } \description{ Summarize number of sightings and animals for selected species by segment } \details{ This function takes the output of \code{\link{das_effort}} and - adds columns for the number of sightings (nSI) and number of animals (ANI) - for selected species (selected via \code{sp.codes}) for each segment - to the segdata element of \code{x.list}. - However, only sightings with an included value of \code{TRUE} - (included is a column in sightinfo) are included in the summaries. - Having this step separate from \code{\link{das_effort}} allows users to - personalize the included values as desired for their analysis. +adds columns for the number of sightings (nSI) and number of animals (ANI) +for selected species (selected via \code{sp.codes}) for each segment +to the segdata element of \code{x.list}. +However, only sightings with an included value of \code{TRUE} +(included is a column in sightinfo) are included in the summaries. +Having this step separate from \code{\link{das_effort}} allows users to +personalize the included values as desired for their analysis. - The ANI columns are the sum of the 'GsSp...' column(s) from - \code{\link{das_sight}} specified using \code{gs.columns}. - If \code{gs.columns} specifies more than one column, - then the secondary columns will only be used if - the values for the previous columns are \code{NA}. - For instance, if \code{gs.columns = c('GsSpBest', 'GsSpLow')}, - then for each row in sightinfo, the value from GsSpLow - will be used only if the value from GsSpBest is \code{NA} +The ANI columns are the sum of the 'GsSp...' column(s) from +\code{\link{das_sight}} specified using \code{gs.columns}. +If \code{gs.columns} specifies more than one column, +then the secondary columns will only be used if +the values for the previous columns are \code{NA}. +For instance, if \code{gs.columns = c('GsSpBest', 'GsSpLow')}, +then for each row in sightinfo, the value from GsSpLow +will be used only if the value from GsSpBest is \code{NA} } \examples{ -y <- system.file("das_sample.das", package = "swfscDAS") +y <- system.file("extdata", "das_sample.das", package = "swfscDAS") y.proc <- das_process(y) y.eff.cond <- das_effort( y.proc, method = "condition", conditions = "Bft", seg.min.km = 0.05, diff --git a/man/das_effort_strata.Rd b/man/das_effort_strata.Rd index 2384095..079f73c 100644 --- a/man/das_effort_strata.Rd +++ b/man/das_effort_strata.Rd @@ -19,35 +19,34 @@ or a data frame that can be coerced to class \code{das_df}} \item{...}{ignored} \item{strata.files}{list of path(s) of the stratum CSV file(s); -see \code{\link{das_effort}}} +see \code{\link[=das_effort]{das_effort()}}} } \value{ -The data frame x, with 1) columns added that - indicate a) if the point was in a particular stratum (see \code{\link{das_intersects_strata}}), and - b) the index of the stratum in \code{strata.files} - (column name 'stratum'; 0 if the point intersects with no strata), and - 2) two rows added for each strata crossing - that occurs between something other than an E and R. - These rows are necessary because of how \code{das_effort} processes effort. - The added rows are the same as the event previous to the strata crossing, except: - \itemize{ - \item They have the event code "strataE" and "strataR", respectively - \item Their coordinates are the coordinates of the intersection of - the effort line and the stratum boundary - \item Their 'idx_eff' values are plus 0.4 and 0.5, respectively - \item The second added row has the same stratum info as the point - immediately after the stratum boundary crossing - } +The data frame x, with 1) columns added that indicate a) if the point was in +a particular stratum (see \code{\link[=das_intersects_strata]{das_intersects_strata()}}), and b) the index of the +stratum in \code{strata.files} (column name 'stratum'; 0 if the point +intersects with no strata), and 2) two rows added for each strata crossing +that occurs between something other than an E and R. These rows are necessary +because of how \code{das_effort} processes effort. The added rows are the +same as the event previous to the strata crossing, except: +\itemize{ +\item They have the event code "strataE" and "strataR", respectively +\item Their coordinates are the coordinates of the intersection of +the effort line and the stratum boundary +\item Their 'idx_eff' values are plus 0.4 and 0.5, respectively +\item The second added row has the same stratum info as the point +immediately after the stratum boundary crossing +} } \description{ Split DAS effort where it intersects with a stratum boundary } \details{ -This function should only be called by \code{\link{das_effort}}, - i.e. it should not be called by users in their personal scripts. - Practically speaking, this functions splits the effort line wherever it crosses a stratum line. - This point of intersection is interpolated; - specifically, it is determined using \code{\link[sf:geos_binary_ops]{st_intersection}}. - Thus, any effort will be first split at these effort-stratum boundary intersection points, - and then using the specified method (e.g. condition). +This function should only be called by \code{\link[=das_effort]{das_effort()}}, i.e. it +should not be called by users in their personal scripts. Practically +speaking, this functions splits the effort line wherever it crosses a stratum +line. This point of intersection is interpolated; specifically, it is +determined using \code{\link[sf:geos_binary_ops]{sf::st_intersection()}}. Thus, any effort will be first +split at these effort-stratum boundary intersection points, and then using +the specified method (e.g. condition). } diff --git a/man/das_format_pdf.Rd b/man/das_format_pdf.Rd index 5b89758..e5cf890 100644 --- a/man/das_format_pdf.Rd +++ b/man/das_format_pdf.Rd @@ -9,23 +9,25 @@ das_format_pdf(file, ...) \arguments{ \item{file}{character, the name of the file where the PDF will be saved} -\item{...}{passed on to \code{\link[base:files]{file.copy}}; might included named argument \code{overwrite}} +\item{...}{passed on to \code{\link[base:files]{base::file.copy()}}; +might included named argument \code{overwrite}} } \value{ -output of \code{\link[base:files]{file.copy}}; - \code{TRUE} if writing of file was successful, and \code{FALSE} otherwise +output of \code{\link[base:files]{base::file.copy()}}; \code{TRUE} if writing of file was successful, +and \code{FALSE} otherwise } \description{ -Save the PDF document describing the DAS format required by \code{swfscDAS} to a specified file +Save the PDF document describing the DAS format required by \code{swfscDAS} +to a specified file } \details{ -A wrapper function for \code{\link[base:files]{file.copy}}. - This function saves the PDF document describing the DAS data format requirements by - copying the PDF document located at \code{system.file("DAS_Format.pdf", package = "swfscDAS")} - to \code{file} +A wrapper function for \code{\link[base:files]{base::file.copy()}}. This function saves the PDF +document describing the DAS data format requirements by copying the PDF +document located at\code{system.file("DAS_Format.pdf", package = "swfscDAS")} to +\code{file} - This file can also be downloaded from - \url{https://github.com/swfsc/swfscDAS/blob/master/inst/DAS_Format.pdf} +This file can also be downloaded from +\url{https://github.com/swfsc/swfscDAS/blob/master/inst/DAS_Format.pdf} } \examples{ das_format_pdf(file.path(tempdir(), "DAS_Format.pdf"), overwrite = FALSE) diff --git a/man/das_intersects_strata.Rd b/man/das_intersects_strata.Rd index 8d82f77..596e1ad 100644 --- a/man/das_intersects_strata.Rd +++ b/man/das_intersects_strata.Rd @@ -45,45 +45,45 @@ See 'Value' section for more details} } \value{ If \code{x} is a data frame, then logical columns are added to \code{x} - indicating if each point intersected with the corresponding stratum polygon. - The names of these columns are the names of \code{strata.files}; - the element(s) of \code{strata.files} will have the name InPoly#, - where '#' is the index of that stratum polygon in \code{strata.files}. - If \code{strata.which}, then the column 'strata_which' is added to the end of the data frame. - This column contains either a 0 if the point intersects with no strata or - 2) a numeric indicating the index (in \code{strata.files}) of - the (first) strata polygon that the point intersects with. - - Otherwise, i.e. if \code{x} is a list and thus the output of one of the effort functions, - then the stratum columns are added to both the segdata and sightinfo data frames. - However, note that the columns added to the sightinfo data frame still indicate - whether or not the segment midpoint was in the corresponding stratum, - rather than the sighting point itself. +indicating if each point intersected with the corresponding stratum polygon. +The names of these columns are the names of \code{strata.files}; the +element(s) of \code{strata.files} will have the name InPoly#, where '#' is +the index of that stratum polygon in \code{strata.files}. If +\code{strata.which}, then the column 'strata_which' is added to the end of +the data frame. This column contains either a 0 if the point intersects with +no strata or 2) a numeric indicating the index (in \code{strata.files}) of +the (first) strata polygon that the point intersects with. + +Otherwise, i.e. if \code{x} is a list and thus the output of one of the +effort functions, then the stratum columns are added to both the segdata and +sightinfo data frames. However, note that the columns added to the sightinfo +data frame still indicate whether or not the segment midpoint was in the +corresponding stratum, rather than the sighting point itself. } \description{ Determine if swfscDAS outputs intersect with strata polygons } \details{ -Assigns DAS event points or segment midpoints to strata polygons - using \code{\link[sf:geos_binary_pred]{st_intersects}}. - - If \code{x} is a list, then 1) it must be the output of - \code{\link{das_effort}} or \code{\link{das_effort_sight}} and - 2) the segment midpoints (column names mlon and mlat, respectively) - are the points checked if they intersect with each provided stratum. - If \code{x} is a data frame, then the user must provide the columns - that specify the point coordinates to check. - - \code{x} should not be an object of class \code{das_dfr}, - or an object of class \code{das_df} created with \code{add.dtll.sight = FALSE}, - because the ? and numeric event codes will have NA latitude and longitude values. +Assigns DAS event points or segment midpoints to strata polygons using +\code{\link[sf:geos_binary_pred]{sf::st_intersects()}}. + +If \code{x} is a list, then 1) it must be the output of +\code{\link{das_effort}} or \code{\link{das_effort_sight}} and 2) the segment +midpoints (column names mlon and mlat, respectively) are the points checked +if they intersect with each provided stratum. If \code{x} is a data frame, +then the user must provide the columns that specify the point coordinates to +check. + +\code{x} should not be an object of class \code{das_dfr}, or an object of +class \code{das_df} created with \code{add.dtll.sight = FALSE}, because the ? +and numeric event codes will have NA latitude and longitude values. } \examples{ -y <- system.file("das_sample.das", package = "swfscDAS") +y <- system.file("extdata", "das_sample.das", package = "swfscDAS") y.proc <- das_process(y) y.eff <- das_effort(y.proc, method = "section", num.cores = 1) -stratum.file <- system.file("das_sample_stratum.csv", package = "swfscDAS") +stratum.file <- system.file("extdata", "das_sample_stratum.csv", package = "swfscDAS") das_intersects_strata(y.eff, list(InPoly = stratum.file), x.lon = "Lon", x.lat = "Lat") das_intersects_strata(y.proc, list(stratum.file)) diff --git a/man/das_process.Rd b/man/das_process.Rd index a43a939..6626a99 100644 --- a/man/das_process.Rd +++ b/man/das_process.Rd @@ -57,39 +57,39 @@ event} } \value{ A \code{das_df} object, which is also a data frame. - It consists of the input data frame, i.e. the output of \code{\link{das_read}}, - with the following columns added: - \tabular{lll}{ - \emph{State/condition} \tab \emph{Column name} \tab \emph{Data source}\cr - On/off effort \tab OnEffort \tab B/R and E events\cr - Cruise number \tab Cruise \tab Event: B; Column: Data1\cr - Effort mode \tab Mode \tab Event: B; Column: Data2\cr - GMT offset of DateTime data \tab OffsetGMT \tab Event: B; Column: Data3\cr - Effort type \tab EffType \tab Event: R; Column: Data1\cr - Number of sides with observer \tab ESWSide \tab Event: R; Column: Data2\cr - Course (ship direction) \tab Course \tab Event: N; Column: Data1\cr - Speed (ship speed, knots) \tab SpdKt \tab Event: N; Column: Data2\cr - Beaufort sea state \tab Bft \tab Event: V; Column: Data1\cr - Swell height (ft) \tab SwellHght \tab Event: V; Column: Data2\cr - Wind speed (knots) \tab WindSpdKt \tab Event: V; Column: Data5\cr - Rain/fog/haze code \tab RainFog \tab Event: W; Column: Data1\cr - Horizontal sun (clock system) \tab HorizSun \tab Event: W; Column: Data2\cr - Vertical sun (clock system) \tab VertSun \tab Event: W; Column: Data3\cr - Glare \tab Glare \tab HorizSun and VertSun\cr - Visibility (nm) \tab Vis \tab Event: W; Column: Data5\cr - Left observer \tab ObsL \tab Event: P; Column: Data1\cr - Data recorder \tab Rec \tab Event: P; Column: Data2\cr - Right observer \tab ObsR \tab Event: P; Column: Data3\cr - Independent observer \tab ObsInd \tab Event: P; Column: Data4\cr - } +It consists of the input data frame, i.e. the output of \code{\link{das_read}}, +with the following columns added: +\tabular{lll}{ +\emph{State/condition} \tab \emph{Column name} \tab \emph{Data source}\cr +On/off effort \tab OnEffort \tab B/R and E events\cr +Cruise number \tab Cruise \tab Event: B; Column: Data1\cr +Effort mode \tab Mode \tab Event: B; Column: Data2\cr +GMT offset of DateTime data \tab OffsetGMT \tab Event: B; Column: Data3\cr +Effort type \tab EffType \tab Event: R; Column: Data1\cr +Number of sides with observer \tab ESWSide \tab Event: R; Column: Data2\cr +Course (ship direction) \tab Course \tab Event: N; Column: Data1\cr +Speed (ship speed, knots) \tab SpdKt \tab Event: N; Column: Data2\cr +Beaufort sea state \tab Bft \tab Event: V; Column: Data1\cr +Swell height (ft) \tab SwellHght \tab Event: V; Column: Data2\cr +Wind speed (knots) \tab WindSpdKt \tab Event: V; Column: Data5\cr +Rain/fog/haze code \tab RainFog \tab Event: W; Column: Data1\cr +Horizontal sun (clock system) \tab HorizSun \tab Event: W; Column: Data2\cr +Vertical sun (clock system) \tab VertSun \tab Event: W; Column: Data3\cr +Glare \tab Glare \tab HorizSun and VertSun\cr +Visibility (nm) \tab Vis \tab Event: W; Column: Data5\cr +Left observer \tab ObsL \tab Event: P; Column: Data1\cr +Data recorder \tab Rec \tab Event: P; Column: Data2\cr +Right observer \tab ObsR \tab Event: P; Column: Data3\cr +Independent observer \tab ObsInd \tab Event: P; Column: Data4\cr +} - OffsetGMT represents the difference in hours between the DateTime data - (which should be in local time) and GMT (i.e., UTC). +OffsetGMT represents the difference in hours between the DateTime data +(which should be in local time) and GMT (i.e., UTC). - Internal warning messages are printed with row numbers of the input file - (NOT of the output data frame) of unexpected event codes and r events, - as well as if there is are potential issues with the number and/or order - of R and E events +Internal warning messages are printed with row numbers of the input file +(NOT of the output data frame) of unexpected event codes and r events, +as well as if there is are potential issues with the number and/or order +of R and E events } \description{ Process DAS data (the output of \code{\link{das_read}}), @@ -97,65 +97,65 @@ including extracting state and condition information for each DAS event } \details{ If \code{x} is a character, - it is assumed to be a file path and first passed to \code{\link{das_read}}. - This output is then passed to \code{das_process}. +it is assumed to be a file path and first passed to \code{\link{das_read}}. +This output is then passed to \code{das_process}. - DAS data is event-based, meaning most events indicate when a state or - weather condition changes. For instance, a 'V' event indicates when one or - more sea state viewing conditions (such as Beaufort sea state) change, and - these conditions are the same for subsequent events until the next 'V' - event. For each state/condition: a new column is created, the - state/condition information is extracted from relevant events, and - extracted information is propagated to appropriate subsequent rows - (events). Thus, each row in the output data frame contains all pertinent - state/condition information for that row. +DAS data is event-based, meaning most events indicate when a state or +weather condition changes. For instance, a 'V' event indicates when one or +more sea state viewing conditions (such as Beaufort sea state) change, and +these conditions are the same for subsequent events until the next 'V' +event. For each state/condition: a new column is created, the +state/condition information is extracted from relevant events, and +extracted information is propagated to appropriate subsequent rows +(events). Thus, each row in the output data frame contains all pertinent +state/condition information for that row. - The following assumptions/decisions are made during processing: - \itemize{ - \item Event codes are expected to be one of the following: - #, *, ?, 1, 2, 3, 4, 5, 6, 7, 8, A, B, C, E, F, k, K, M, N, - P, Q, r, R, s, S, t, V, W, g, G, p, X, Y, Z - \item All '#' events (deleted events) are removed - \item r events are converted to R events with non-standard effort; - see \code{\link{das_format_pdf}} for more details - \item An event is considered 'on effort' if it is 1) an R event, - 2) a B event immediately preceding an R event, or - 3) between corresponding R and E events (not including the E event). The - 'EffortDot' column is not used when determining on effort data. Note that - effort is reset to 'off effort' at the beginning of a new day. - \item All state/condition information is reset at the beginning of each - cruise. New cruises are identified using \code{days.gap}. - \item All state/condition information relating to B, R, P, V, N, and W - events are reset every time there is a BR event sequence if - \code{reset.effort == TRUE}, because in WinCruz a BR event sequence - should always be a BRPVNW event sequence. An event sequence means that - all of the events have the same Lat/Lon/DateTime info, and thus previous - values for conditions set during the event sequence should not carry over - to any part of the event sequence. - \item 'OffsetGMT' is converted to an integer. Values are expected to be - consistent within a day for each cruise, so events will have an OffsetGMT - value if there is any B event with the offset data on the same day, - whether that event is before or after the B event. Thus, if any - date/cruise combinations have multiple OffsetGMT values in the data, then - a warning message will be printed and the OffsetGMT values will be all NA - (for the entire output).#' - \item 'Mode' is capitalized, and 'Mode' values of \code{NA} are assigned - a value of "C" - \item 'EffType' is capitalized, and values of \code{NA} are assigned a - value of "S" - \item 'ESWsides' represents the number of sides being searched during - that effort section - a value of \code{NA} (for compatibility with older - data) or "F" means 2 sides are being searched, and a value of "H" means 1 - side is being searched. ESWsides will be \code{NA} for values that are - not one of "F", \code{NA}, or "H" - \item 'Glare': \code{TRUE} if 'HorizSun' is 11, 12 or 1 and 'VertSun' is - 2 or 3, or if 'HorizSun' is 12 and 'VertSun' is 1; \code{NA} if - 'HorizSun' or 'VertSun' is \code{NA}; otherwise \code{FALSE} - \item Missing values are \code{NA} rather than \code{-1} - } +The following assumptions/decisions are made during processing: +\itemize{ +\item Event codes are expected to be one of the following: +#, *, ?, 1, 2, 3, 4, 5, 6, 7, 8, A, B, C, E, F, k, K, M, N, +P, Q, r, R, s, S, t, V, W, g, G, p, X, Y, Z +\item All '#' events (deleted events) are removed +\item r events are converted to R events with non-standard effort; +see \code{\link{das_format_pdf}} for more details +\item An event is considered 'on effort' if it is 1) an R event, +2) a B event immediately preceding an R event, or +3) between corresponding R and E events (not including the E event). The +'EffortDot' column is not used when determining on effort data. Note that +effort is reset to 'off effort' at the beginning of a new day. +\item All state/condition information is reset at the beginning of each +cruise. New cruises are identified using \code{days.gap}. +\item All state/condition information relating to B, R, P, V, N, and W +events are reset every time there is a BR event sequence if +\code{reset.effort == TRUE}, because in WinCruz a BR event sequence +should always be a BRPVNW event sequence. An event sequence means that +all of the events have the same Lat/Lon/DateTime info, and thus previous +values for conditions set during the event sequence should not carry over +to any part of the event sequence. +\item 'OffsetGMT' is converted to an integer. Values are expected to be +consistent within a day for each cruise, so events will have an OffsetGMT +value if there is any B event with the offset data on the same day, +whether that event is before or after the B event. Thus, if any +date/cruise combinations have multiple OffsetGMT values in the data, then +a warning message will be printed and the OffsetGMT values will be all NA +(for the entire output).#' +\item 'Mode' is capitalized, and 'Mode' values of \code{NA} are assigned +a value of "C" +\item 'EffType' is capitalized, and values of \code{NA} are assigned a +value of "S" +\item 'ESWsides' represents the number of sides being searched during +that effort section - a value of \code{NA} (for compatibility with older +data) or "F" means 2 sides are being searched, and a value of "H" means 1 +side is being searched. ESWsides will be \code{NA} for values that are +not one of "F", \code{NA}, or "H" +\item 'Glare': \code{TRUE} if 'HorizSun' is 11, 12 or 1 and 'VertSun' is +2 or 3, or if 'HorizSun' is 12 and 'VertSun' is 1; \code{NA} if +'HorizSun' or 'VertSun' is \code{NA}; otherwise \code{FALSE} +\item Missing values are \code{NA} rather than \code{-1} +} } \examples{ -y <- system.file("das_sample.das", package = "swfscDAS") +y <- system.file("extdata", "das_sample.das", package = "swfscDAS") das_process(y) y.read <- das_read(y) diff --git a/man/das_read.Rd b/man/das_read.Rd index 48e5972..0173df7 100644 --- a/man/das_read.Rd +++ b/man/das_read.Rd @@ -9,75 +9,75 @@ das_read(file, skip = 0, ...) \arguments{ \item{file}{file name(s) of one or more DAS files} -\item{skip}{integer; see \code{\link[readr]{read_fwf}}. Default is 0} +\item{skip}{integer; see \code{\link[readr:read_fwf]{readr::read_fwf()}}. Default is 0} \item{...}{ignored} } \value{ -A \code{das_dfr} object, which is also a data frame, with DAS data - read into columns. The data are read into the data frame as characters as - described in 'Details', with the following exceptions: - \tabular{lll}{ - \emph{Name} \tab \emph{Class} \tab \emph{Details}\cr - EffortDot \tab logical \tab \code{TRUE} if "." was present, and \code{FALSE} otherwise\cr - DateTime \tab POSIXct \tab combination of 'Date' and 'Time' columns\cr - Lat \tab numeric \tab 'Latitude' column converted to decimal degrees in range [-90, 90]\cr - Lon \tab numeric \tab 'Longitude' column converted to decimal degrees in range [-180, 180]\cr - Data# \tab character \tab leading/trailing whitespace trimmed for non-comment events (i.e. where 'Event' is not "C")\cr - EventNum \tab character \tab leading/trailing whitespace trimmed; left as character for some project-specific codes\cr - file_das \tab character \tab base filename, extracted from the \code{file} argument\cr - line_num \tab integer \tab line number of each data row\cr - } +A \code{das_dfr} object, which is also a data frame, with DAS data read into +columns. The data are read into the data frame as characters as described in +'Details', with the following exceptions: +\tabular{lll}{ +\emph{Name} \tab \emph{Class} \tab \emph{Details}\cr +EffortDot \tab logical \tab \code{TRUE} if "." was present, and \code{FALSE} otherwise\cr +DateTime \tab POSIXct \tab combination of 'Date' and 'Time' columns\cr +Lat \tab numeric \tab 'Latitude' column converted to decimal degrees in range \link{-90, 90}\cr +Lon \tab numeric \tab 'Longitude' column converted to decimal degrees in range \link{-180, 180}\cr +Data# \tab character \tab leading/trailing whitespace trimmed for non-comment events (i.e. where 'Event' is not "C")\cr +EventNum \tab character \tab leading/trailing whitespace trimmed; left as character for some project-specific codes\cr +file_das \tab character \tab base filename, extracted from the \code{file} argument\cr +line_num \tab integer \tab line number of each data row\cr +} - DateTime values have a time zone value (i.e., a tzone attribute) of "". - Note that this means RStudio will print these datetimes with the local - timezone See the OffsetGMT column from \code{\link{das_process}} for - relevant time zone information +DateTime values have a time zone value (i.e., a tzone attribute) of "". Note +that this means RStudio will print these datetimes with the local timezone +See the OffsetGMT column from \code{\link{das_process}} for relevant time +zone information - Warnings are printed if any unexpected events have \code{NA} - DateTime/Lat/Lon values, or if any Lat/Lon values cannot be converted to - numeric values. Events that are 'expected' to have \code{NA} - DateTime/Lat/Lon values are: C, ?, 1, 2, 3, 4, 5, 6, 7, 8 +Warnings are printed if any unexpected events have \code{NA} DateTime/Lat/Lon +values, or if any Lat/Lon values cannot be converted to numeric values. +Events that are 'expected' to have \code{NA} DateTime/Lat/Lon values are: C, +?, 1, 2, 3, 4, 5, 6, 7, 8 } \description{ Read one or more fixed-width DAS text file(s) generated by WinCruz into a data frame, where each line is data for a specific event } \details{ -Reads/parses DAS data into columns of a data frame. - If \code{file} contains multiple file names, then the individual - data frames will be concatenated. +Reads/parses DAS data into columns of a data frame. If \code{file} contains +multiple file names, then the individual data frames will be concatenated. - The provided DAS file must adhere to the following column number and format - specifications: - \tabular{lrr}{ - \emph{Item} \tab \emph{Columns} \tab \emph{Format}\cr - Event number \tab 1-3 \tab \cr - Event \tab 4 \tab \cr - Effort dot \tab 5 \tab \cr - Time \tab 6-11 \tab HHMMSS or HHMM\cr - Date \tab 13-18 \tab MMDDYY\cr - Latitude \tab 20-28 \tab NDD:MM.MM\cr - Longitude \tab 30-39 \tab WDDD:MM.MM\cr - Data1 \tab 40-44 \tab \cr - Data2 \tab 45-49 \tab \cr - Data3 \tab 50-54 \tab \cr - Data4 \tab 55-59 \tab \cr - Data5 \tab 60-64 \tab \cr - Data6 \tab 65-69 \tab \cr - Data7 \tab 70-74 \tab \cr - Data8 \tab 75-79 \tab \cr - Data9 \tab 80-84 \tab \cr - Data10 \tab 85-89 \tab \cr - Data11 \tab 90-94 \tab \cr - Data12 \tab 95+ \tab \cr - } +The provided DAS file must adhere to the following column number and format +specifications: +\tabular{lrr}{ +\emph{Item} \tab \emph{Columns} \tab \emph{Format}\cr +Event number \tab 1-3 \tab \cr +Event \tab 4 \tab \cr +Effort dot \tab 5 \tab \cr +Time \tab 6-11 \tab HHMMSS or HHMM\cr +Date \tab 13-18 \tab MMDDYY\cr +Latitude \tab 20-28 \tab NDD:MM.MM\cr +Longitude \tab 30-39 \tab WDDD:MM.MM\cr +Data1 \tab 40-44 \tab \cr +Data2 \tab 45-49 \tab \cr +Data3 \tab 50-54 \tab \cr +Data4 \tab 55-59 \tab \cr +Data5 \tab 60-64 \tab \cr +Data6 \tab 65-69 \tab \cr +Data7 \tab 70-74 \tab \cr +Data8 \tab 75-79 \tab \cr +Data9 \tab 80-84 \tab \cr +Data10 \tab 85-89 \tab \cr +Data11 \tab 90-94 \tab \cr +Data12 \tab 95+ \tab \cr +} - See \code{\link{das_format_pdf}} for more information about DAS format requirements, and - note that 'Data#' columns may be referred to as 'Field#' columns in other documentation. +See \code{\link{das_format_pdf}} for more information about DAS format +requirements, and note that 'Data#' columns may be referred to as 'Field#' +columns in other documentation. } \examples{ -y <- system.file("das_sample.das", package = "swfscDAS") +y <- system.file("extdata", "das_sample.das", package = "swfscDAS") das_read(y) } diff --git a/man/das_segdata.Rd b/man/das_segdata.Rd index fefbecf..68d47e8 100644 --- a/man/das_segdata.Rd +++ b/man/das_segdata.Rd @@ -39,8 +39,8 @@ section for more information} section)} } \value{ -Data frame with the segdata information described in Details - and in \code{\link{das_effort}} +Data frame with the segdata information described in Details and in +\code{\link{das_effort}} } \description{ Summarize DAS effort data by effort segment, while averaging or getting the @@ -48,43 +48,42 @@ max for each condition } \details{ WARNING - do not call this function directly! It is exported for - documentation purposes, but is intended for internal package use only. +documentation purposes, but is intended for internal package use only. - This function was designed to be called by one of the das_chop_ functions, - e.g. \code{\link{das_chop_equallength}}, and thus users should avoid - calling it themselves. It loops through the events in \code{x}, chopping - \code{x} into modeling segments while calculating and storing relevant - information for each segment. Because \code{x} is a continuous effort - section, it must begin with a "B" or "R" event and end with the - corresponding "E" event. +This function was designed to be called by one of the das_chop_ functions, +e.g. \code{\link{das_chop_equallength}}, and thus users should avoid calling +it themselves. It loops through the events in \code{x}, chopping \code{x} +into modeling segments while calculating and storing relevant information for +each segment. Because \code{x} is a continuous effort section, it must begin +with a "B" or "R" event and end with the corresponding "E" event. - For each segment, this function reports the segment number, segment ID, - cruise number, the start/end/mid coordinates (lat/lon), start/end/mid - date/times (DateTime), segment length, year, month, day, midpoint time, - mode, OffsetGMT value, effort type, effective strip width sides (number of - sides searched), and average conditions (which are specified by - \code{conditions}). The segment ID is designated as \code{section.id} _ - index of the modeling segment. Thus, if \code{section.id} is \code{1}, then - the segment ID for the second segment from \code{x} is \code{"1_2"}. The - start/end coordinates and date/times are interpolated as needed, e.g. when - using the 'equallength' method. +For each segment, this function reports the segment number, segment ID, +cruise number, the start/end/mid coordinates (lat/lon), start/end/mid +date/times (DateTime), segment length, year, month, day, midpoint time, mode, +OffsetGMT value, effort type, effective strip width sides (number of sides +searched), and average conditions (which are specified by \code{conditions}). +The segment ID is designated as \code{section.id} _ index of the modeling +segment. Thus, if \code{section.id} is \code{1}, then the segment ID for the +second segment from \code{x} is \code{"1_2"}. The start/end coordinates and +date/times are interpolated as needed, e.g. when using the 'equallength' +method. - When \code{segdata.method} is "avg", the condition values are calculated as - a weighted average by distance. The reported value for logical columns - (e.g. Glare) is the percentage (in decimals) of the segment in which that - condition was \code{TRUE}. For character columns, the reported value for - each segment is the unique value(s) present in the segment, with \code{NA}s - omitted, pasted together via \code{paste(..., collapse = "; ")}. When - \code{segdata.method} is "maxdist", the reported values are, for each - condition, the value recorded for the longest distance during that segment - (with \code{NA}s omitted). +When \code{segdata.method} is "avg", the condition values are calculated as a +weighted average by distance. The reported value for logical columns (e.g. +Glare) is the percentage (in decimals) of the segment in which that condition +was \code{TRUE}. For character columns, the reported value for each segment +is the unique value(s) present in the segment, with \code{NA}s omitted, +pasted together via \code{paste(..., collapse = "; ")}. When +\code{segdata.method} is "maxdist", the reported values are, for each +condition, the value recorded for the longest distance during that segment +(with \code{NA}s omitted). - Cruise number, mode, effort type, sides searched, and file name are also - included in the segdata output. These values (excluding \code{NA}s) must be - consistent across the entire effort section, and thus across all segments - in \code{x}; a warning is printed if there are any inconsistencies +Cruise number, mode, effort type, sides searched, and file name are also +included in the segdata output. These values (excluding \code{NA}s) must be +consistent across the entire effort section, and thus across all segments in +\code{x}; a warning is printed if there are any inconsistencies - \code{\link[swfscMisc]{bearing}} and \code{\link[swfscMisc]{destination}} - are used to calculate the segment start, mid, and end points, with - \code{method = "vincenty"}. +\code{\link[swfscMisc]{bearing}} and \code{\link[swfscMisc]{destination}} are +used to calculate the segment start, mid, and end points, with \code{method = +"vincenty"}. } diff --git a/man/das_sight.Rd b/man/das_sight.Rd index 0ed877c..eb3fdc1 100644 --- a/man/das_sight.Rd +++ b/man/das_sight.Rd @@ -32,187 +32,193 @@ Must be one or more of: "S", "K", "M", "G", "s", "k", "m", "g", "t", "p", "F" } \value{ Data frame with 1) the columns from \code{x}, excluding the 'Data#' columns, - and 2) columns with sighting information extracted from 'Data#' columns. - See \code{\link{das_format_pdf}} for more information the sighting information. - If \code{return.format} is "default", then there is one row for each species of each sighting event; - if \code{return.format} is "wide", then there is one row for each sighting event; - if \code{return.format} is "complete", then there is one row for every - group size estimate for each sighting event (excluding sperm whale "C" events - see the Details section). - - The format-specific columns are described in their respective sections. - The following sighting information columns are included in all return formats: - - \tabular{lll}{ - \emph{Sighting information} \tab \emph{Column name} \tab \emph{Notes} \cr - Sighting number \tab SightNo \tab Character \cr - Subgroup code \tab Subgroup \tab Character \cr - Daily sighting number \tab SightNoDaily \tab See below \cr - Observer that made the sighting \tab Obs \tab \cr - Standard observer \tab ObsStd \tab Logical; \code{TRUE} if Obs is one of ObsL, Rec or ObsR, and \code{FALSE} otherwise \cr - Bearing to the sighting \tab Bearing \tab Numeric; degrees, expected range 0 to 360 \cr - Number of reticle marks \tab Reticle \tab Numeric \cr - Distance (nautical miles) \tab DistNm \tab Numeric \cr - Sighting cue \tab Cue \tab \cr - Sighting method \tab Method \tab \cr - Photos of school? \tab Photos \tab \cr - Birds present with school? \tab Birds \tab \cr - Calibration school? \tab CalibSchool \tab \cr - Aerial photos taken? \tab PhotosAerial \tab \cr - Biopsy taken? \tab Biopsy \tab \cr - Probable sighting \tab Prob \tab Logical indicating if sighting has associated ? event; \code{NA} for non-S/K/M/G events\cr - Number of species in sighting \tab nSp \tab \code{NA} for non-S/K/M/G events \cr - Mixed species sighting \tab Mixed \tab Logical; \code{TRUE} if nSp > 1 \cr - Group size of school - best estimate \tab GsSchoolBest \tab See below \cr - Group size of school - high estimate \tab GsSchoolHigh \tab See below \cr - Group size of school - low estimate \tab GsSchoolLow \tab See below \cr - Course (true heading) of school at resight \tab CourseSchool \tab \code{NA} for non-s/k/m events \cr - Presence of associated JFR \tab TurtleJFR \tab \code{NA} for non-"t" events; JFR = jellyfish, floating debris, or red tide \cr - Estimated turtle maturity \tab TurtleAge \tab \code{NA} for non-"t" events \cr - Perpendicular distance (km) to sighting \tab PerpDistKm \tab Calculated via \code{(abs(sin(Bearing*pi/180) * DistNm) * 1.852)} - } - - SightNoDaily is a running count of the number of S/K/M/G sightings that occurred on each day. - It is formatted as 'YYYYMMDD'_'running count', e.g. "20050101_1". - - The GsSchoolBest, GsSchoolHigh, and GsSchoolLow columns are either: - 1) the arithmetic mean across observer estimates, for the "default" and "wide" formats, or - 2) the individual observer estimates, for the "complete" format. - Note that for non-"complete" formats, \code{na.rm = TRUE} is used when calculating the mean, - and thus blank elements of estimates (but not the whole incomplete estimate) are ignored. - - To convert the perpendicular distance back to nautical miles, - one would divide PerpDistKm by 1.852 +and 2) columns with sighting information extracted from 'Data#' columns. See +\code{\link{das_format_pdf}} for more information the sighting information. +If \code{return.format} is "default", then there is one row for each species +of each sighting event; if \code{return.format} is "wide", then there is one +row for each sighting event; if \code{return.format} is "complete", then +there is one row for every group size estimate for each sighting event +(excluding sperm whale "C" events - see the Details section). + +The format-specific columns are described in their respective sections. The +following sighting information columns are included in all return formats: + +\tabular{lll}{ +\emph{Sighting information} \tab \emph{Column name} \tab \emph{Notes} \cr +Sighting number \tab SightNo \tab Character \cr +Subgroup code \tab Subgroup \tab Character \cr +Daily sighting number \tab SightNoDaily \tab See below \cr +Observer that made the sighting \tab Obs \tab \cr +Standard observer \tab ObsStd \tab Logical; \code{TRUE} if Obs is one of ObsL, Rec or ObsR, and \code{FALSE} otherwise \cr +Bearing to the sighting \tab Bearing \tab Numeric; degrees, expected range 0 to 360 \cr +Number of reticle marks \tab Reticle \tab Numeric \cr +Distance (nautical miles) \tab DistNm \tab Numeric \cr +Sighting cue \tab Cue \tab \cr +Sighting method \tab Method \tab \cr +Photos of school? \tab Photos \tab \cr +Birds present with school? \tab Birds \tab \cr +Calibration school? \tab CalibSchool \tab \cr +Aerial photos taken? \tab PhotosAerial \tab \cr +Biopsy taken? \tab Biopsy \tab \cr +Probable sighting \tab Prob \tab Logical indicating if sighting has associated ? event; \code{NA} for non-S/K/M/G events\cr +Number of species in sighting \tab nSp \tab \code{NA} for non-S/K/M/G events \cr +Mixed species sighting \tab Mixed \tab Logical; \code{TRUE} if nSp > 1 \cr +Group size of school - best estimate \tab GsSchoolBest \tab See below \cr +Group size of school - high estimate \tab GsSchoolHigh \tab See below \cr +Group size of school - low estimate \tab GsSchoolLow \tab See below \cr +Course (true heading) of school at resight \tab CourseSchool \tab \code{NA} for non-s/k/m events \cr +Presence of associated JFR \tab TurtleJFR \tab \code{NA} for non-"t" events; JFR = jellyfish, floating debris, or red tide \cr +Estimated turtle maturity \tab TurtleAge \tab \code{NA} for non-"t" events \cr +Perpendicular distance (km) to sighting \tab PerpDistKm \tab Calculated via \code{(abs(sin(Bearing*pi/180) * DistNm) * 1.852)} +} + +SightNoDaily is a running count of the number of S/K/M/G sightings that +occurred on each day. It is formatted as 'YYYYMMDD'_'running count', e.g. +"20050101_1". + +The GsSchoolBest, GsSchoolHigh, and GsSchoolLow columns are either: 1) the +arithmetic mean across observer estimates, for the "default" and "wide" +formats, or 2) the individual observer estimates, for the "complete" format. +Note that for non-"complete" formats, \code{na.rm = TRUE} is used when +calculating the mean, and thus blank elements of estimates (but not the whole +incomplete estimate) are ignored. + +To convert the perpendicular distance back to nautical miles, one would +divide PerpDistKm by 1.852 } \description{ Extract sightings and associated information from processed DAS data } \details{ -DAS events contain specific information in the 'Data#' columns, - with the information depending on the event code for that row. - The output data frame contains columns with this specific information - extracted to dedicated columns as described below. - This function recognizes the following types of sightings: - marine mammal sightings (event codes "S", "K", or "M"), - marine mammal resights (codes "s", "k", "m"), - marine mammal subgroup sightings (code "G"), - marine mammal subgroup resights (code "g"), - turtle sightings (code "t"), - pinniped sightings (code "p"), - and fishing vessel sightings (code "F"). - Warnings are printed if all S, K, M, and G events (and only these events) are not - followed by an A event and at least one numeric event. - See \code{\link{das_format_pdf}} for more information about events and event formats. - Of specific note - sperm whale sightings (species code 046) often contain additional estimates - recorded as "C" events immediately following the S, A, and numeric events. - Because these estimates are recorded as"C" events, they are NOT included in the - \code{das_sight} calculations or output for any \code{return.format} - - The \code{return.events} argument simply provides a shortcut for - filtering the output of \code{das_sight} by event codes - - Abbreviations used in output column names: Gs = group size, Sp = species, - Nm = nautical mile, Perc = percentage, Prob = probable, - GsSchool = school-level group size info - - This function makes the following assumptions, and alterations to the raw DAS data: - \itemize{ - \item "A" events immediately following an S/K/M/G event have - the same sighting number (Data1 value) as the S/K/M/G event - \item The 'nSp' column is equivalent to the number of non-\code{NA} values across the - 'Data5', 'Data6', 'Data7', and 'Data8' columns - for the pertinent "A" event - \item The following data are coerced to a numeric using - \code{\link[base:numeric]{as.numeric}}: - Bearing, Reticle, DistNm, Cue, Method, - species percentages, and group sizes (including for t, p, and F events). - Note that if there are any formatting errors and these data are not numeric, - the function will likely print a warning message - \item The values for the following columns are capitalized using - \code{\link[base:chartr]{toupper}}: - 'Birds', 'Photos', 'CalibSchool', 'PhotosAerial', 'Biopsy', - 'TurtleAge', and 'TurtleCapt' - } +DAS events contain specific information in the 'Data#' columns, with the +information depending on the event code for that row. The output data frame +contains columns with this specific information extracted to dedicated +columns as described below. This function recognizes the following types of +sightings: marine mammal sightings (event codes "S", "K", or "M"), marine +mammal resights (codes "s", "k", "m"), marine mammal subgroup sightings (code +"G"), marine mammal subgroup resights (code "g"), turtle sightings (code +"t"), pinniped sightings (code "p"), and fishing vessel sightings (code "F"). +Warnings are printed if all S, K, M, and G events (and only these events) are +not followed by an A event and at least one numeric event. See +\code{\link{das_format_pdf}} for more information about events and event +formats. Of specific note - sperm whale sightings (species code 046) often +contain additional estimates recorded as "C" events immediately following the +S, A, and numeric events. Because these estimates are recorded as"C" events, +they are NOT included in the \code{das_sight} calculations or output for any +\code{return.format} + +The \code{return.events} argument simply provides a shortcut for filtering +the output of \code{das_sight} by event codes + +Abbreviations used in output column names: Gs = group size, Sp = species, Nm += nautical mile, Perc = percentage, Prob = probable, GsSchool = school-level +group size info + +This function makes the following assumptions, and alterations to the raw DAS +data: +\itemize{ +\item "A" events immediately following an S/K/M/G event have +the same sighting number (Data1 value) as the S/K/M/G event +\item The 'nSp' column is equivalent to the number of non-\code{NA} values across the +'Data5', 'Data6', 'Data7', and 'Data8' columns +for the pertinent "A" event +\item The following data are coerced to a numeric using +\code{\link[base:numeric]{as.numeric}}: +Bearing, Reticle, DistNm, Cue, Method, +species percentages, and group sizes (including for t, p, and F events). +Note that if there are any formatting errors and these data are not numeric, +the function will likely print a warning message +\item The values for the following columns are capitalized using +\code{\link[base:chartr]{toupper}}: +'Birds', 'Photos', 'CalibSchool', 'PhotosAerial', 'Biopsy', +'TurtleAge', and 'TurtleCapt' +} } \section{The "default" format output}{ - This output data frame contains 'long' sighting data, meaning there is one row for each species of each sighting event. - The GsSp... columns are calculated as follows: - for each species and for each observer estimate, the best/high/low school size estimate is multiplied by the applicable species percent estimate. - The values are grouped by species and then averaged to get single GsSpBest, GsSpHigh, and GsSpLow values for each species. - (using \code{\link[base]{mean}} with \code{na.rm = TRUE}) - - Sighting information columns/formats present specifically in the "default" format output: - \tabular{lll}{ - \emph{Sighting information} \tab \emph{Column name} \tab \emph{Notes}\cr - Species code \tab SpCode \tab Boat type or mammal, turtle, or pinniped species codes\cr - Probable species code \tab SpCodeProb \tab Probable mammal species codes; \code{NA} if none or not applicable\cr - Group size of species - best estimate \tab GsSpBest \tab - The product of the arithmetic means of GsSchoolBest and the corresponding species percentage\cr - Group size of species - high estimate \tab GsSpHigh \tab - The product of the arithmetic means of GsSchoolHigh and the corresponding species percentage\cr - Group size of species - low estimate \tab GsSpLow \tab - The product of the arithmetic means of GsSchoolLow and the corresponding species percentage\cr - } - - Note that for the above calculations, - the GsSchoolX value and corresponding species percentages were each - averaged across observers, using \code{na.rm = TRUE}, - before being multiplied to calculate GsSpX. For example, in the workflow: - \code{GsSpBest1 = mean(.data$Data2, na.rm = TRUE) * mean(.data$Data5, na.rm = TRUE)} +This output data frame contains 'long' sighting data, meaning there is one +row for each species of each sighting event. The GsSp... columns are +calculated as follows: for each species and for each observer estimate, the +best/high/low school size estimate is multiplied by the applicable species +percent estimate. The values are grouped by species and then averaged to get +single GsSpBest, GsSpHigh, and GsSpLow values for each species. (using +\code{\link[base]{mean}} with \code{na.rm = TRUE}) + +Sighting information columns/formats present specifically in the "default" +format output: +\tabular{lll}{ +\emph{Sighting information} \tab \emph{Column name} \tab \emph{Notes}\cr +Species code \tab SpCode \tab Boat type or mammal, turtle, or pinniped species codes\cr +Probable species code \tab SpCodeProb \tab Probable mammal species codes; \code{NA} if none or not applicable\cr +Group size of species - best estimate \tab GsSpBest \tab +The product of the arithmetic means of GsSchoolBest and the corresponding species percentage\cr +Group size of species - high estimate \tab GsSpHigh \tab +The product of the arithmetic means of GsSchoolHigh and the corresponding species percentage\cr +Group size of species - low estimate \tab GsSpLow \tab +The product of the arithmetic means of GsSchoolLow and the corresponding species percentage\cr +} + +Note that for the above calculations, the GsSchoolX value and corresponding +species percentages were each averaged across observers, using \code{na.rm + = TRUE}, before being multiplied to calculate GsSpX. For example, in the +workflow: \code{GsSpBest1 = mean(.data$Data2, na.rm = TRUE) * + mean(.data$Data5, na.rm = TRUE)} } \section{The "wide" and "complete" format outputs}{ - The "wide" and "complete" options have very similar columns in their output date frames. - There are two main differences: 1) the "wide" format has one row for each sighting event, - while the complete format has a row for every observer estimate for each sightings, and thus - 2) in the "wide" format, all numeric information for which there are multiple observer estimates - (school group size, species percentage, etc.) are averaged across estimated via - an arithmetic mean (using \code{\link[base]{mean}} with \code{na.rm = TRUE}) - - With these formats, note that the species/type code and group size for - turtle, pinniped, and boat sightings are in their own column - - Sighting information columns present in the "wide" and "complete" format outputs: - \tabular{lll}{ - \emph{Sighting information} \tab \emph{Column name} \tab \emph{Notes} \cr - Observer code - estimate \tab ObsEstimate \tab See below \cr - Species 1 code \tab SpCode1 \tab \cr - Species 2 code \tab SpCode2 \tab \cr - Species 3 code \tab SpCode3 \tab \cr - Species 4 code \tab SpCode4 \tab \cr - Species 1 probable code \tab SpCodeProb1 \tab Extracted from '?' event \cr - Species 2 probable code \tab SpCodeProb2 \tab Extracted from '?' event \cr - Species 3 probable code \tab SpCodeProb3 \tab Extracted from '?' event \cr - Species 4 probable code \tab SpCodeProb4 \tab Extracted from '?' event \cr - Percentage of Sp 1 in school \tab SpPerc1 \tab \cr - Percentage of Sp 2 in school \tab SpPerc2 \tab \cr - Percentage of Sp 3 in school \tab SpPerc3 \tab \cr - Percentage of Sp 4 in school \tab SpPerc4 \tab \cr - Group size of species 1 \tab GsSpBest1 \tab Present in "wide" output only; see below\cr - Group size of species 2 \tab GsSpBest2 \tab Present in "wide" output only; see below\cr - Group size of species 3 \tab GsSpBest3 \tab Present in "wide" output only; see below\cr - Group size of species 4 \tab GsSpBest4 \tab Present in "wide" output only; see below\cr - Turtle species \tab TurtleSp \tab \code{NA} for non-"t" events \cr - Turtle group size \tab TurtleGs \tab \code{NA} for non-"t" events \cr - Was turtle captured? \tab TurtleCapt \tab \code{NA} for non-"t" events \cr - Pinniped species \tab PinnipedSp \tab \code{NA} for non-"p" events \cr - Pinniped group size \tab PinnipedGs \tab \code{NA} for non-"p" events \cr - Boat or gear type \tab BoatType \tab \code{NA} for non-"F" events \cr - Number of boats \tab BoatGs \tab \code{NA} for non-"F" events - } - - ObsEstimate refers to the code of the observer that made the corresponding estimate. - For the "wide" format, ObsEstimate is a list-column of all of the observer codes - that provided an estimate. - Also in the "wide" format, the GsSpBest# columns are the product of - the means of GsSchoolBest and the corresponding species percentage - (see the Default section for calculation details). - These numbers, 1 to 4, correspond to the order of the data as it appears in the DAS file +The "wide" and "complete" options have very similar columns in their output +date frames. There are two main differences: 1) the "wide" format has one row +for each sighting event, while the complete format has a row for every +observer estimate for each sightings, and thus 2) in the "wide" format, all +numeric information for which there are multiple observer estimates (school +group size, species percentage, etc.) are averaged across estimated via an +arithmetic mean (using \code{\link[base]{mean}} with \code{na.rm = TRUE}) + +With these formats, note that the species/type code and group size for +turtle, pinniped, and boat sightings are in their own column + +Sighting information columns present in the "wide" and "complete" format +outputs: +\tabular{lll}{ +\emph{Sighting information} \tab \emph{Column name} \tab \emph{Notes} \cr +Observer code - estimate \tab ObsEstimate \tab See below \cr +Species 1 code \tab SpCode1 \tab \cr +Species 2 code \tab SpCode2 \tab \cr +Species 3 code \tab SpCode3 \tab \cr +Species 4 code \tab SpCode4 \tab \cr +Species 1 probable code \tab SpCodeProb1 \tab Extracted from '?' event \cr +Species 2 probable code \tab SpCodeProb2 \tab Extracted from '?' event \cr +Species 3 probable code \tab SpCodeProb3 \tab Extracted from '?' event \cr +Species 4 probable code \tab SpCodeProb4 \tab Extracted from '?' event \cr +Percentage of Sp 1 in school \tab SpPerc1 \tab \cr +Percentage of Sp 2 in school \tab SpPerc2 \tab \cr +Percentage of Sp 3 in school \tab SpPerc3 \tab \cr +Percentage of Sp 4 in school \tab SpPerc4 \tab \cr +Group size of species 1 \tab GsSpBest1 \tab Present in "wide" output only; see below\cr +Group size of species 2 \tab GsSpBest2 \tab Present in "wide" output only; see below\cr +Group size of species 3 \tab GsSpBest3 \tab Present in "wide" output only; see below\cr +Group size of species 4 \tab GsSpBest4 \tab Present in "wide" output only; see below\cr +Turtle species \tab TurtleSp \tab \code{NA} for non-"t" events \cr +Turtle group size \tab TurtleGs \tab \code{NA} for non-"t" events \cr +Was turtle captured? \tab TurtleCapt \tab \code{NA} for non-"t" events \cr +Pinniped species \tab PinnipedSp \tab \code{NA} for non-"p" events \cr +Pinniped group size \tab PinnipedGs \tab \code{NA} for non-"p" events \cr +Boat or gear type \tab BoatType \tab \code{NA} for non-"F" events \cr +Number of boats \tab BoatGs \tab \code{NA} for non-"F" events +} + +ObsEstimate refers to the code of the observer that made the corresponding +estimate. For the "wide" format, ObsEstimate is a list-column of all of the +observer codes that provided an estimate. Also in the "wide" format, the +GsSpBest# columns are the product of the means of GsSchoolBest and the +corresponding species percentage (see the Default section for calculation +details). These numbers, 1 to 4, correspond to the order of the data as it +appears in the DAS file } \examples{ -y <- system.file("das_sample.das", package = "swfscDAS") +y <- system.file("extdata", "das_sample.das", package = "swfscDAS") y.proc <- das_process(y) das_sight(y.proc) diff --git a/man/das_spcodes.Rd b/man/das_spcodes.Rd new file mode 100644 index 0000000..9374000 --- /dev/null +++ b/man/das_spcodes.Rd @@ -0,0 +1,38 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/das_spcodes.R +\name{das_spcodes} +\alias{das_spcodes} +\alias{das_spcodes_read} +\title{Read DAS SpCodes file} +\usage{ +das_spcodes_read(file, skip = 0) +} +\arguments{ +\item{file}{character; filename of .dat file from which to read +species codes} + +\item{skip}{integer; default is 3. +Number of lines to skip when reading SpCodes file. +See \code{\link[readr:read_fwf]{readr::read_fwf()}} for more details} +} +\value{ +Data frame with four columns: +\itemize{ +\item SpCode: species code, columns 1 to 4 +\item Abbr: species abbreviation, columns 6 to 15 +\item SciName: species scientific name, columns 18 to 57 +\item CommonName: species common name, columns 58 until the end of the line +} +} +\description{ +Read DAS SpCodes file +} +\details{ +Provide a standardized function to read a shipboard DAS SpCodes file. +Methods described in 'returns' +} +\examples{ +sp.codes.file <- system.file("extdata", "SpCodes_sample.dat", package = "swfscDAS") +das_spcodes_read(sp.codes.file) + +} diff --git a/man/randpicks_convert.Rd b/man/randpicks_convert.Rd index 08b8806..9cd71a6 100644 --- a/man/randpicks_convert.Rd +++ b/man/randpicks_convert.Rd @@ -15,16 +15,17 @@ randpick values formatted for segchopr that correspond to \code{x.segdata}} \item{seg.km}{numeric; target segment length used when creating \code{x.segdata}} } \value{ -Data frame with one line for each continuous effort section in \code{x.segdata}, - and two columns: \code{effort_section} and \code{randpicks} +Data frame with one line for each continuous effort section in +\code{x.segdata}, and two columns: \code{effort_section} and \code{randpicks} } \description{ Convert randpicks file from segchopr format to swfscDAS format } \details{ -Past DAS processing code (segchopr) only recorded the generated random values, - whereas swfscDAS randpicks files contain one line for each continuous effort section. - See \code{\link{das_chop_equallength}} for more details about the swfscDAS randpicks format. - This function 'converts' a randpicks data frame generated by segchopr - to a data frame that meets the swfscDAS randpicks format requirements +Past DAS processing code (segchopr) only recorded the generated random +values, whereas swfscDAS randpicks files contain one line for each continuous +effort section. See \code{\link{das_chop_equallength}} for more details about +the swfscDAS randpicks format. This function 'converts' a randpicks data +frame generated by segchopr to a data frame that meets the swfscDAS randpicks +format requirements } diff --git a/man/subsetting.Rd b/man/subsetting.Rd index f6f0cf6..4970c24 100644 --- a/man/subsetting.Rd +++ b/man/subsetting.Rd @@ -43,19 +43,20 @@ Subsetting \code{das_dfr} or \code{das_df} objects } \details{ -When subsetting a \code{das_dfr} or \code{das_df} object, henceforth a \code{das_} object, -using any of the functions described in \code{\link[base]{[.data.frame}}, -then then the \code{das_} class is simply dropped and the object is of class \code{data.frame}. -This is because of the strict format requirements of \code{das_} objects; -it is likely that a subsetted \code{das_} object will not have -the format required by subsequent swfscDAS functions, -and thus it is safest to drop the \code{das_} class. -If a data frame is passed to downstream \code{swfscDAS} functions that require a \code{das_} object, -then they will attempt to coerce the object to the necessary \code{das_} class -See \code{\link{as_das_dfr}} and \code{\link{as_das_df}} for more details. +When subsetting a \code{das_dfr} or \code{das_df} object, henceforth a +\code{das_} object, using any of the functions described in +\code{\link[base]{[.data.frame}}, then then the \code{das_} class is simply +dropped and the object is of class \code{data.frame}. This is because of the +strict format requirements of \code{das_} objects; it is likely that a +subsetted \code{das_} object will not have the format required by subsequent +swfscDAS functions, and thus it is safest to drop the \code{das_} class. If a +data frame is passed to downstream \code{swfscDAS} functions that require a +\code{das_} object, then they will attempt to coerce the object to the +necessary \code{das_} class See \code{\link{as_das_dfr}} and +\code{\link{as_das_df}} for more details. } \examples{ -y <- system.file("das_sample.das", package = "swfscDAS") +y <- system.file("extdata", "das_sample.das", package = "swfscDAS") y.read <- das_read(y) # All return a data frame: diff --git a/tests/testthat/test-class.R b/tests/testthat/test-class.R index 454837b..21904df 100644 --- a/tests/testthat/test-class.R +++ b/tests/testthat/test-class.R @@ -1,5 +1,5 @@ test_that("functions return expected das_ classes", { - y.read <- das_read(system.file("das_sample.das", package = "swfscDAS")) + y.read <- das_read(system.file("extdata", "das_sample.das", package = "swfscDAS")) y.proc <- das_process(y.read) y.sight <- das_sight(y.proc) @@ -10,7 +10,7 @@ test_that("functions return expected das_ classes", { test_that("as_das_ functions work as expected", { - y.read <- das_read(system.file("das_sample.das", package = "swfscDAS")) + y.read <- das_read(system.file("extdata", "das_sample.das", package = "swfscDAS")) y.proc <- das_process(y.read) y.read1 <- y.read2 <- y.read3 <- y.read diff --git a/tests/testthat/test-das_check.R b/tests/testthat/test-das_check.R index 78e97af..c1b5adf 100644 --- a/tests/testthat/test-das_check.R +++ b/tests/testthat/test-das_check.R @@ -1,6 +1,8 @@ test_that("das_check no error output", { - y.check <- das_check(system.file("das_sample.das", package = "swfscDAS"), - print.cruise.nums = FALSE) + y.check <- das_check( + system.file("extdata", "das_sample.das", package = "swfscDAS"), + print.cruise.nums = FALSE + ) exp.df <- data.frame( File = NA, LineNum = NA, CruiseNum = NA, ID = NA, diff --git a/tests/testthat/test-effort_strata.R b/tests/testthat/test-effort_strata.R index 85429c0..71094fe 100644 --- a/tests/testthat/test-effort_strata.R +++ b/tests/testthat/test-effort_strata.R @@ -1,8 +1,8 @@ test_that("effort distance and sightings are the same with or without strata splitting", { - y <- system.file("das_sample.das", package = "swfscDAS") + y <- system.file("extdata", "das_sample.das", package = "swfscDAS") y.proc <- das_process(y) - stratum.file <- system.file("das_sample_stratum.csv", package = "swfscDAS") - # y.rand <- system.file("das_sample_randpicks.csv", package = "swfscDAS") + stratum.file <- system.file("extdata", "das_sample_stratum.csv", package = "swfscDAS") + # y.rand <- system.file("extdata", "das_sample_randpicks.csv", package = "swfscDAS") # Using "condition" method eff.cond.nostrata <- das_effort( diff --git a/tests/testthat/test-output.R b/tests/testthat/test-output.R index 8e7e82c..9aa916d 100644 --- a/tests/testthat/test-output.R +++ b/tests/testthat/test-output.R @@ -1,4 +1,4 @@ -y.read <- das_read(system.file("das_sample.das", package = "swfscDAS")) +y.read <- das_read(system.file("extdata", "das_sample.das", package = "swfscDAS")) y.proc <- das_process(y.read) diff --git a/tests/testthat/test-process.R b/tests/testthat/test-process.R index da419ba..3915c3c 100644 --- a/tests/testthat/test-process.R +++ b/tests/testthat/test-process.R @@ -1,5 +1,5 @@ test_that("Arguments are passed correctly between _process and _read", { - y <- system.file("das_sample.das", package = "swfscDAS") + y <- system.file("extdata", "das_sample.das", package = "swfscDAS") y.read <- das_read(y, skip = 20) y.proc <- das_process(y.read, reset.effort = FALSE) diff --git a/tests/testthat/test-subsetting.R b/tests/testthat/test-subsetting.R index cc05103..e708245 100644 --- a/tests/testthat/test-subsetting.R +++ b/tests/testthat/test-subsetting.R @@ -1,5 +1,5 @@ test_that("subsetting das_ objects returns a data frame", { - y.read <- das_read(system.file("das_sample.das", package = "swfscDAS")) + y.read <- das_read(system.file("extdata", "das_sample.das", package = "swfscDAS")) y.proc <- das_process(y.read) expect_identical("data.frame", class(y.read[, 1:10])) diff --git a/tests/testthat/test-zero_sighting_events.R b/tests/testthat/test-zero_sighting_events.R index f7b5829..44eb508 100644 --- a/tests/testthat/test-zero_sighting_events.R +++ b/tests/testthat/test-zero_sighting_events.R @@ -1,4 +1,4 @@ -y <- system.file("das_sample.das", package = "swfscDAS") +y <- system.file("extdata", "das_sample.das", package = "swfscDAS") y.read <- das_read(y, skip = 20, tz = "GMT") y.proc <- das_process(y.read, reset.effort = FALSE) diff --git a/vignettes/DAS_data_join.Rmd b/vignettes/DAS_data_join.Rmd index 05330bd..23638e7 100644 --- a/vignettes/DAS_data_join.Rmd +++ b/vignettes/DAS_data_join.Rmd @@ -27,7 +27,7 @@ It is common when processing DAS data to use a text-based DAT file to provide ad First we read in and process the sample DAS data ```{r das} -y <- system.file("das_sample.das", package = "swfscDAS") +y <- system.file("extdata", "das_sample.das", package = "swfscDAS") y.proc <- das_process(y) y.sight <- das_sight(y.proc, return.format = "default") ``` @@ -36,18 +36,14 @@ This package includes Ships_sample.dat and SpCodes_sample.dat files, which have ```{r dat} ships.df <- data.frame(read_fwf( - system.file("Ship_sample.dat", package = "swfscDAS"), + system.file("extdata", "Ship_sample.dat", package = "swfscDAS"), col_positions = fwf_widths(c(6, NA), col_names = c("Cruise", "Ship")), col_types = cols(Cruise = col_double(), Ship = col_character()), trim_ws = TRUE ), stringsAsFactors = FALSE) -spcodes.df <- data.frame(read_fwf( - system.file("SpCodes_sample.dat", package = "swfscDAS"), - col_positions = fwf_widths(c(4, 13, 40, NA), col_names = c("SpCode", "Abbr", "SciName", "CommonName")), - col_types = cols(.default = col_character()), - trim_ws = TRUE -), stringsAsFactors = FALSE) +spcodes.file <- system.file("extdata", "SpCodes_sample.dat", package = "swfscDAS") +spcodes.df <- das_spcodes_read(spcodes.file) ``` ## Join data diff --git a/vignettes/swfscDAS.Rmd b/vignettes/swfscDAS.Rmd index bcea762..87028fd 100644 --- a/vignettes/swfscDAS.Rmd +++ b/vignettes/swfscDAS.Rmd @@ -29,7 +29,7 @@ In DAS data, an event is only recorded when something changes or happens, which This package includes a sample DAS file, which we will use in this document ```{r data} -y <- system.file("das_sample.das", package = "swfscDAS") +y <- system.file("extdata", "das_sample.das", package = "swfscDAS") head(readLines(y)) ``` @@ -140,7 +140,7 @@ This package contains several methods to incorporate strata into your DAS data p First, `das_intersects_strata` allows you to add columns to data frames indicating if a point intersects one or more strata polygons. You can pass this function either a data frame or a list. If a list then it must be the output of `das_effort` or `das_effort_sight`, and the function will use the segment midpoints to determine if a segment (and associated sightings) intersected each stratum. ```{r strata_int} -stratum.file <- system.file("das_sample_stratum.csv", package = "swfscDAS") +stratum.file <- system.file("extdata", "das_sample_stratum.csv", package = "swfscDAS") y.eff.sight.strata <- das_intersects_strata(y.eff.sight, list(InPoly = stratum.file)) glimpse(y.eff.sight.strata$segdata) From ff2988c282f148c623249e178285f50932ccb29c Mon Sep 17 00:00:00 2001 From: Sam Woodman - NOAA Date: Mon, 11 Aug 2025 16:03:57 -0700 Subject: [PATCH 2/6] doc fix --- R/das_read.R | 4 ++-- man/das_read.Rd | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/R/das_read.R b/R/das_read.R index 7e1bcc1..604c5a2 100644 --- a/R/das_read.R +++ b/R/das_read.R @@ -48,8 +48,8 @@ #' \emph{Name} \tab \emph{Class} \tab \emph{Details}\cr #' EffortDot \tab logical \tab \code{TRUE} if "." was present, and \code{FALSE} otherwise\cr #' DateTime \tab POSIXct \tab combination of 'Date' and 'Time' columns\cr -#' Lat \tab numeric \tab 'Latitude' column converted to decimal degrees in range [-90, 90]\cr -#' Lon \tab numeric \tab 'Longitude' column converted to decimal degrees in range [-180, 180]\cr +#' Lat \tab numeric \tab 'Latitude' column converted to decimal degrees in range `[-90, 90]`\cr +#' Lon \tab numeric \tab 'Longitude' column converted to decimal degrees in range `[-180, 180]`\cr #' Data# \tab character \tab leading/trailing whitespace trimmed for non-comment events (i.e. where 'Event' is not "C")\cr #' EventNum \tab character \tab leading/trailing whitespace trimmed; left as character for some project-specific codes\cr #' file_das \tab character \tab base filename, extracted from the \code{file} argument\cr diff --git a/man/das_read.Rd b/man/das_read.Rd index 0173df7..a8e7628 100644 --- a/man/das_read.Rd +++ b/man/das_read.Rd @@ -21,8 +21,8 @@ columns. The data are read into the data frame as characters as described in \emph{Name} \tab \emph{Class} \tab \emph{Details}\cr EffortDot \tab logical \tab \code{TRUE} if "." was present, and \code{FALSE} otherwise\cr DateTime \tab POSIXct \tab combination of 'Date' and 'Time' columns\cr -Lat \tab numeric \tab 'Latitude' column converted to decimal degrees in range \link{-90, 90}\cr -Lon \tab numeric \tab 'Longitude' column converted to decimal degrees in range \link{-180, 180}\cr +Lat \tab numeric \tab 'Latitude' column converted to decimal degrees in range \verb{[-90, 90]}\cr +Lon \tab numeric \tab 'Longitude' column converted to decimal degrees in range \verb{[-180, 180]}\cr Data# \tab character \tab leading/trailing whitespace trimmed for non-comment events (i.e. where 'Event' is not "C")\cr EventNum \tab character \tab leading/trailing whitespace trimmed; left as character for some project-specific codes\cr file_das \tab character \tab base filename, extracted from the \code{file} argument\cr From cb9259103eb1f4bcd66ac7a76c0c1bf3a56211c5 Mon Sep 17 00:00:00 2001 From: Sam Woodman - NOAA Date: Mon, 11 Aug 2025 16:25:33 -0700 Subject: [PATCH 3/6] added spcodes --- NEWS.md | 4 + inst/extdata/SpCodes.dat | 190 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 194 insertions(+) create mode 100644 inst/extdata/SpCodes.dat diff --git a/NEWS.md b/NEWS.md index 80d8309..485a99f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,10 +2,14 @@ * Added an exported function `das_spcodes_read` for consistent reading of shipboard SpCode files +* Changed the argument name in `das_check` of the user-provided SpCodes file from `sp.codes` to `sp.codes.file`. Also added a `sp.codes.skip` argument to pass to `das_spcodes_read` + * Moved example data files to an 'extdata' folder within 'inst' * Update roxygen to use markdown +* Added the SpCodes.dat file from [`CruzPlot`](https://github.com/SWFSC/CruzPlot) to 'inst' to have available as a default + # swfscDAS 0.6.4 diff --git a/inst/extdata/SpCodes.dat b/inst/extdata/SpCodes.dat new file mode 100644 index 0000000..0d11610 --- /dev/null +++ b/inst/extdata/SpCodes.dat @@ -0,0 +1,190 @@ + 001 MESOP_PERU Mesoplodon peruvianus Pygmy beaked whale + 002 OFFSH_SPOT Stenella attenuata (offshore) Offshore pantropical spotted dolphin, offshore spotter + 003 UNID_SPINR Stenella longirostris (unid. subsp.) Unidentified spinner dolphin, spinner porpoise + 004 CLYMENE Stenella clymene Clymene dolphin, short-snouted spinner dolphin + 005 UNID_COMM Delphinus sp. Unidentified common dolphin, saddleback dolphin, whitebelly porpoise + 006 COAST_SPOT Stenella attenuata graffmani Coastal spotted dolphin, spotter, silverbacks + 007 SOTALIA Sotalia fluviatilis Tucuxi, Guiana dolphin + 008 ORCAELLA Orcaella brevirostris Irrawaddy dolphin, Lumbalumba + 009 SPECTACLED Phocoena dioptrica Spectacled porpoise + 010 EAST_SPINR Stenella longirostris orientalis Eastern spinner dolphin + 011 WBEL_SPINR Stenella longirostris (whitebelly) Whitebelly spinner dolphin + 012 WHITE-BEAK Lagenorhynchus albirostris White-beaked dolphin + 013 STRIPED Stenella coeruleoalba Striped dolphin, streaker porpoise, euphrosyne dolphin + 014 A_WHT_SIDE Lagenorhynchus acutus Atlantic white-sided dolphin + 015 STENO Steno bredanensis Rough-toothed dolphin, Steno + 016 LONGB_COMM Delphinus capensis Long-beaked common dolphin, Baja neritic common dolphin + 017 SHRTB_COMM Delphinus delphis Short-beaked common dolphin, offshore common dolphin + 018 TURSIOPS Tursiops truncatus Bottlenose dolphin, black porpoise, common porpoise + 019 HEAVISIDES Cephalorhynchus heavisidii Heaviside's dolphin + 020 HECTORS Cephalorhynchus hectori Hector's dolphin, pied dolphin, white front dolphin + 021 GRAMPUS Grampus griseus Risso's dolphin, gray grampus + 022 P_WHT_SIDE Lagenorhynchus obliquidens Pacific white-sided dolphin, lag, hookfin porpoise + 023 PEALES Lagenorhynchus australis Peale's dolphin, blackchin dolphin + 024 HOURGLASS Lagenorhynchus cruciger Hourglass dolphin + 025 DUSKY Lagenorhynchus obscurus Dusky dolphin + 026 FRASERS Lagenodelphis hosei Fraser's dolphin, Sarawak dolphin + 027 LISSO_BOR Lissodelphis borealis Northern right whale dolphin + 028 LISSO_PER Lissodelphis peronii Southern right whale dolphin + 029 BLACK_DOL Cephalorhynchus eutropia Black dolphin, Chilean dolphin + 030 COMMERSONS Cephalorhynchus commersonii Commerson's dolphin, piebald dolphin + 031 MELON_HEAD Peponocephala electra Melon-headed whale, Hawaiian/many-toothed blackfish, electra dolphin + 032 PYGMY_KLLR Feresa attenuata Pygmy killer whale, slender blackfish + 033 FALSE_KLLR Pseudorca crassidens False killer whale + 034 GLOBI_SPP Globicephala sp. Unidentified pilot whale + 035 LONG_PILOT Globicephala melas Long-finned pilot whale, Atlantic pilot whale, blackfish, pothead + 036 SHRT_PILOT Globicephala macrorhynchus Short-finned pilot whale, blackfish, pothead + 037 KILLER_WHA Orcinus orca Killer whale + 038 SOUSA_CHIN Sousa chinensis Indo-Pacific hump-backed dolphin, white dolphin + 039 SOUSA_TEUS Sousa teuszii Atlantic hump-backed dolphin + 040 HARBR_PORP Phocoena phocoena Harbor porpoise, herring hog + 041 VAQUITA Phocoena sinus Vaquita, Gulf of California harbor porpoise + 042 BURMEISTER Phocoena spinipinnis Burmeister's porpoise, black porpoise + 043 BL_FINLESS Neophocaena phocaenoides Black finless porpoise + 044 DALLS_PORP Phocoenoides dalli Dall's porpoise + 045 BELUGA Delphinapterus leucas Beluga, white whale, belukha, sea canary + 046 SPERM_WHAL Physeter macrocephalus Sperm whale + 047 PYGMYSPERM Kogia breviceps Pygmy sperm whale + 048 DWARFSPERM Kogia sima Dwarf sperm whale + 049 ZIPHIID_WH Ziphiid whale Unidentified beaked whale + 050 HYPERO_PLN Hyperoodon planifrons Southern bottlenose whale, flathead bottlenose whale + 051 MESOP_SPP Mesoplodon sp. Unidentified Mesoplodon + 052 MESOP_CARL Mesoplodon carlhubbsi Hubb's beaked whale, archbeak whale + 053 MESOP_HECT Mesoplodon hectori Hector's beaked whale + 054 MESOP_BOWD Mesoplodon bowdoini Andrew's beaked whale, deepcrest whale + 055 MESOP_EURO Mesoplodon europaeus Gervais' beaked whale, Antillean beaked whale + 056 MESOP_BDNS Mesoplodon bidens Sowerby's beaked whale + 057 MESOP_GNKO Mesoplodon ginkgodens Ginkgo-toothed beaked whale + 058 MESOP_GRAY Mesoplodon grayi Gray's beaked whale + 059 MESOP_DENS Mesoplodon densirostris Blaineville's beaked whale, dense-beaked, tropical beaked whale + 060 MESOP_LAYA Mesoplodon layardii Strap-toothed whale + 061 ZIPHI_CAVI Ziphius cavirostris Cuvier's beaked whale, goose-beaked whale + 062 BERARD_ARN Berardius arnuxii Arnoux's beaked whale, southern giant bottlenose whale + 063 BERARD_BAI Berardius bairdii Baird's beaked whale, northern giant bottlenose whale + 064 TASMA_SHEP Tasmacetus shepherdi Shepherd's beaked whale + 065 INDOPAC_PAC Indopacetus pacificus Longman's beaked whale + 066 NPAC_RT_WH Eubalaena japonica North Pacific right whale + 067 BOWHEAD_WH Balaena mysticetus Bowhead whale + 068 PYGMY_RGHT Caperea marginata Pygmy right whale + 069 GRAY_WHALE Eschrichtius robustus Gray whale + 070 UNID_RORQL Balaenopterid sp Unidentified rorqual (Balaenoptera, Megaptera) + 071 MINKE_WHAL Balaenoptera acutorostrata Common minke whale + 072 BRYDES_WHL Balaenoptera edeni Bryde's whale + 073 SEI_WHALE Balaenoptera borealis Sei whale + 074 FIN_WHALE Balaenoptera physalus Fin whale + 075 BLUE_WHALE Balaenoptera musculus Blue whale + 076 HUMPBACK_W Megaptera novaeangliae Humpback whale + 077 UNID_DOLPH Unidentified dolphin or porpoise + 078 UNID_SM_WH Unidentified small whale + 079 UNID_LG_WH Unidentified large whale + 080 KOGIA_SPP Kogia sp. Unidentified Kogia - dwarf or pygmy sperm whale + 081 MESOP_STEJ Mesoplodon stejnegeri Steinger's beaked whale, sabertooth, Bering Sea beaked whale + 082 MESOP_MIRU Mesoplodon mirus True's beaked whale + 083 MESOP_SP_A Mesoplodon sp. A Unnamed beaked whale + 084 HYPERO_AMP Hyperoodon ampullatus Northern bottlenose whale, North Atlantic bottlenose whale + 085 NARWHAL Monodon monoceros Narwhal, sea unicorn + 086 S_RIGHT_WH Eubalaena australis Southern right whale + 087 FRANCISCAN Pontoporia blainvillei Franciscana, La Plata dolphin + 088 C_A_SPINNR Stenella longirostris centroamericana Central American spinner dolphin, Costa Rican spinner dolphin + 089 UNID_SPOT Stenella attenuata/plagidon Unidentified spotted dolphin in Atlantic + 090 UNID_SPOT Stenella attenuata (unid. subsp.) Unidentified pantropical spotted dolphin, spotter porpoise + 091 AT_SPOTTED Stenella frontalis Atlantic spotted dolphin, spotter porpoise + 092 GANGES_DOL Platanista gangetica gangetica Ganges river dolphin + 093 INDUS_DOL Platanista gangetica minor Indus river dolphin + 094 INIA Inia geoffrensis Boto, Amazon river dolphin + 095 LIPOTES Lipotes vexillifer Baiji, Chinese river dolphin, whitefin dolphin + 096 UNID_CETAC Unidentified cetacean + 097 UNID_OBJCT Unidentified object, possible marine mammal + 098 UNID_WHALE Unidentified whale + 099 SEI/BRYDES Balaenoptera borealis/edeni Rorqual identified as a Sei or Bryde's whale + 100 TRESMARIAS Stenella longirostris (Tres Marias) Tres Marias spinner dolphin + 101 SW_SPINNER Stenella longirostris (southwestern) Southwestern spinner dolphin + 102 GRAYS_SPIN Stenella longirostris (Gray's) Gray's spinner dolphin, pantropical spinner dolphin + 103 E/CA_SPIN Stenella longirostris orient/centroam Undetermined eastern or Central American spinner dolphin + 104 ANTC_MINKE Balaenoptera bonaerensis Antarctic minke whale + 105 IO_BTLNOSE Tursiops aduncas Indian Ocean bottlenose dolphin + 106 Mesoplodon traversii spade-toothed whale + 107 DWF_SPINNR Stenella longirostris roseiventris Dwarf spinner dolphin + 108 NATL_RT_WH Eubalaena glacialis North Atlantic right whale + 109 Mesoplodon perrini Perrin's beaked whale + 110 Orcinus orca Transient killer whale + 111 Orcinus orca Resident killer whale + 112 Orcinus orca Offshore killer whale + 113 Orcinus orca Type A Antarctic killer whale + 114 Orcinus orca Type B Antarctic killer whale + 115 Orcinus orca Type C Antarctic killer whale + 116 Tursiops truncatus California coastal bottlenose dolphin + 117 Tursiops truncatus California offshore bottlenose dolphin + 118 Balaenoptera omurai Omura's whale + 119 Sotalia guianensis Costero + 120 Orcaella heinsohni Australian snubfin dolphin + 149 Unidentified small beaked whale (includes Mesoplodon and Ziphius; excludes Berardius; since 4/2007) + 177 UNID_S_DEL unid. small delphinid Unidentified small delphinid (Delphinus, Lagenorhynchus, Lissodelphis or Stenella) + 189 Mesoplodon hotaula + 197 Unidentified marine mammal (since 4/2007) + 199 Balaenoptera physalus/borealis/edeni Rorqual identified as Fin, Sei, or Bryde's + 277 UNID_M_DEL unid. medium delphinid Unidentified medium delphinid (Feresa, Grampus, Steno or Tursiops) + 377 UNID_L_DEL unid. large delphinid Unidentified large delphinid (Pseudorca, Orca or Globicephala) U + 477 UNID_PORP unid. porpoise Unidentified porpoise (Phocoena or Phocoenoides) + 800 Wooly mammoth (in temporary use only, 9/20/2004) + 801 Bison species (in temporary use only, 9/20/2004) + AP Arctocephalus pusillus Tasmanian and Cape fur seals + AR Arctocephalus tropicalis Subantarctic fur seal + AH Arctocephalus philippii Juan Fernandez fur seal + AA Arctocephalus australis South American fur seal + AF Arctocephalus forsteri New Zealand fur seal + AG Arctocephalus galapagoensis Galapagos fur seal + AT GUAD_FURSL Arctocephalus townsendi Guadalupe fur seal + AZ Arctocephalus gazella Antarctic fur seal + CT Cystophora cristata Hooded seal + CU NO_FURSEAL Callorhinus ursinus Northern fur seal + EB Erignathus barbatus Bearded seal + EJ STELLAR_SL Eumetopias jubatus Steller sea lion + HP Halichoerus grypus Gray seal + MA N_ELEPHN_S Mirounga angustirostris Northern elephant seal + ML S_ELEPHN_S Mirounga leonina Southern elephant seal + MS Monachus schauinslandi Hawaiian monk seal + MP Monochus tropicalis Caribbean or West Indian monk seal + OB SA_SEALION Otaria flavescens South American sea lion + OR Odobenus rosmarus Pacific walrus + OS Ommatophoca rossii Ross Seal + PC CASPN_SEAL Pusa caspica Caspian seal + PF Histriophoca fasciata Ribbon seal + PG Pagophilus groenlandicus Harp seal + PH Pusa hispida Ringed seal + PL Phoca largha Spotted seal + PS Pusa sibirica Baikal seal + MO Monachus monachus Mediterranean monk seal + LE Leptonychotes weddellii Weddell seal + LC Lobodon carcinophaga Crabeater seal + HL Hydrurga leptonyx Leopard seal + PU UNID_PINNI unid. pinniped Unidentified Pinniped + PV HARBR_SEAL Phoca vitulina Harbor seal + UA UNID_FURSL unid. fur seal Unidentified fur seal + UO UNID_OTARI unid. sea lion Unidentified sea lion + US UNID_SEAL unid. seal Unidentified seal + ZC CA_SEALION Zalophus californianus California sea lion + ZJ Zalophus japonicus Japanese sea lion + ZW Zalophus wollebaeki Galapagos sea lion + PK Phocarctos hookeri New Zealand sea lion, Hooker's sea lion + NC Neophoca cinerea Australian sea lion + EL Enhydra lutris Sea otter + LF Lontra felina Marine otter, chungungo + HG Hydrodamalis gigas Stellar sea cow + TI Trichechus inunguis Amazon manatee + TM Trichechus manatus West Indian manatee + TS Trichechus senegalensis African manatee, West African manatee + DG Dugong dugon Dugong, sea cow + UM Ursus maritimus Polar bear + CC Caretta Caretta Loggerhead sea turtle + CM Chelonia mydas/agassizi Green/Black sea turtle + DC Dermochelys coriacea Leatherback sea turtle + EI Eretmochelys imbricata Hawksbill sea turtle + HT Hybrid sea turtle + LK Lepidochelys kempi Kemp's Ridley turtle + LV Lepidochelys olivacea Olive Ridley sea turtle + ND Natator depressus Flatback turtle + UH Other than D. coriacea Unidentified hardshell sea turtle + UT Chelonidae Unidentified sea turtle + RT Rhincodon typus Whale shark + UU Unidentified. Unknown origin From 0de9e39139f5a9edab1190cf6970066b969cc544 Mon Sep 17 00:00:00 2001 From: Sam Woodman - NOAA Date: Mon, 11 Aug 2025 16:28:30 -0700 Subject: [PATCH 4/6] add examples --- R/das_check.R | 4 ++++ man/das_check.Rd | 4 ++++ vignettes/DAS_data_join.Rmd | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/R/das_check.R b/R/das_check.R index 8fc09ca..9344212 100644 --- a/R/das_check.R +++ b/R/das_check.R @@ -96,6 +96,10 @@ #' y <- system.file("extdata", "das_sample.das", package = "swfscDAS") #' if (interactive()) das_check(y) #' +#' # Using your own SpCodes file +#' sp.codes.file <- system.file("extdata", "SpCodes.dat", package = "swfscDAS") +#' if (interactive()) das_check(y, sp.codes.file = sp.codes.file) +#' #' @export das_check <- function( file, diff --git a/man/das_check.Rd b/man/das_check.Rd index bd81b62..d71dbe5 100644 --- a/man/das_check.Rd +++ b/man/das_check.Rd @@ -116,4 +116,8 @@ And that each has at least one group size estimate (1:8 event) y <- system.file("extdata", "das_sample.das", package = "swfscDAS") if (interactive()) das_check(y) +# Using your own SpCodes file +sp.codes.file <- system.file("extdata", "SpCodes.dat", package = "swfscDAS") +if (interactive()) das_check(y, sp.codes.file = sp.codes.file) + } diff --git a/vignettes/DAS_data_join.Rmd b/vignettes/DAS_data_join.Rmd index 23638e7..8e62f68 100644 --- a/vignettes/DAS_data_join.Rmd +++ b/vignettes/DAS_data_join.Rmd @@ -42,7 +42,7 @@ ships.df <- data.frame(read_fwf( trim_ws = TRUE ), stringsAsFactors = FALSE) -spcodes.file <- system.file("extdata", "SpCodes_sample.dat", package = "swfscDAS") +spcodes.file <- system.file("extdata", "SpCodes.dat", package = "swfscDAS") spcodes.df <- das_spcodes_read(spcodes.file) ``` From f09781bd0ac5d53a731d14a0b2e73a41db7f5b4b Mon Sep 17 00:00:00 2001 From: Sam Woodman - NOAA Date: Mon, 20 Jul 2026 21:57:06 -0700 Subject: [PATCH 5/6] version bump to v0.6.5 dev. Fixes #17 --- DESCRIPTION | 6 +++--- NAMESPACE | 2 ++ NEWS.md | 7 +++++++ R/das_effort_strata.R | 2 ++ R/swfscDAS-package.R | 7 ++----- README.md | 2 +- man/swfscAirDAS-internals.Rd | 5 +++-- vignettes/swfscDAS.Rmd | 3 ++- 8 files changed, 22 insertions(+), 12 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index fb2e489..8ab2be7 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,11 +1,11 @@ Package: swfscDAS Title: Processing DAS Data Files -Version: 0.6.4 +Version: 0.6.5.9000 Authors@R: person("Sam", "Woodman", email = "sam.woodman@noaa.gov", role = c("aut", "cre"), comment = c(ORCID = "0000-0001-6071-8186")) Description: Process and summarize DAS data files. These files are typically, but do not have to be - DAS data + DAS data produced by the Southwest Fisheries Science Center (SWFSC) program 'WinCruz'. This package standardizes and streamlines basic DAS data processing, and includes a PDF with the DAS data format requirements expected by the package. @@ -31,5 +31,5 @@ Suggests: testthat (>= 2.1.0) License: Apache License (== 2) Encoding: UTF-8 -RoxygenNote: 7.3.2 VignetteBuilder: knitr +Config/roxygen2/version: 8.0.0 diff --git a/NAMESPACE b/NAMESPACE index a257432..fe85fc0 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -23,6 +23,8 @@ S3method(das_comments,das_dfr) S3method(das_comments,data.frame) S3method(das_effort,das_df) S3method(das_effort,data.frame) +S3method(das_effort_strata,das_df) +S3method(das_effort_strata,data.frame) S3method(das_intersects_strata,data.frame) S3method(das_intersects_strata,list) S3method(das_process,character) diff --git a/NEWS.md b/NEWS.md index cc4b8f8..87d3a8a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,10 @@ +# swfscDAS 0.6.5 (dev) + +* Update link to NOAA Tech Memo describing DAS data; now (https://repository.library.noaa.gov/view/noaa/3174)[https://repository.library.noaa.gov/view/noaa/3174](#17) + +* Fix documentation issues realted to upgrade to roxygen2 v8.0 + + # swfscDAS 0.6.4 * The DateTime column in `das_read` output now has a timezone of `""` (#13) diff --git a/R/das_effort_strata.R b/R/das_effort_strata.R index dcfd4f5..e90f72d 100644 --- a/R/das_effort_strata.R +++ b/R/das_effort_strata.R @@ -36,11 +36,13 @@ das_effort_strata <- function(x, ...) UseMethod("das_effort_strata") #' @name das_effort_strata +#' @exportS3Method das_effort_strata.data.frame <- function(x, ...) { das_effort_strata(as_das_df(x), ...) } #' @name das_effort_strata +#' @exportS3Method das_effort_strata.das_df <- function(x, strata.files, ...) { # Check that none of the strata overlap strata.list <- lapply(strata.files, .das_pts2poly_vertices) #duplication, oh well diff --git a/R/swfscDAS-package.R b/R/swfscDAS-package.R index 2836a95..d49bb46 100644 --- a/R/swfscDAS-package.R +++ b/R/swfscDAS-package.R @@ -12,9 +12,7 @@ #' @author Sam Woodman \email{sam.woodman@@noaa.gov} #' @seealso \url{https://swfsc.github.io/swfscDAS/} #' -#' @importFrom dplyr add_row arrange between bind_cols bind_rows case_when desc -#' distinct everything filter full_join group_by if_else lag left_join mutate -#' n n_distinct reframe right_join select slice starts_with summarise ungroup +#' @importFrom dplyr add_row arrange between bind_cols bind_rows case_when desc distinct everything filter full_join group_by if_else lag left_join mutate n n_distinct reframe right_join select slice starts_with summarise ungroup #' @importFrom lubridate year month day tz #' @importFrom magrittr %>% #' @importFrom methods setOldClass @@ -22,8 +20,7 @@ #' @importFrom readr cols col_character fwf_positions read_fwf #' @importFrom rlang !! .data #' @importFrom purrr map_chr pmap pmap_int pmap_lgl -#' @importFrom sf st_as_sf st_cast st_coordinates st_geometry st_intersects -#' st_intersection st_linestring st_polygon st_sf st_sfc st_wrap_dateline +#' @importFrom sf st_as_sf st_cast st_coordinates st_geometry st_intersects st_intersection st_linestring st_polygon st_sf st_sfc st_wrap_dateline #' @importFrom stats na.omit runif #' @importFrom swfscMisc bearing destination distance setupClusters #' @importFrom tidyr pivot_longer diff --git a/README.md b/README.md index 1839c4d..ed04174 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ [![R-CMD-check](https://github.com/swfsc/swfscDAS/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/swfsc/swfscDAS/actions/workflows/R-CMD-check.yaml) -This package contains functions designed for processing and analyzing shipboard DAS data. This package was originally designed to handle [DAS data](https://swfsc-publications.fisheries.noaa.gov/publications/TM/SWFSC/NOAA-TM-NMFS-SWFSC-305.PDF) collected using WinCruz, the ship-based line-transect data collection software developed by the Southwest Fisheries Science Center. However, the `swfscDAS` package can be used by anyone who has collected DAS data that meets the format requirements described in the ['DAS data format'](#DAS-data-format) section below, for instance to process decades of available NOAA Fisheries DAS survey data. +This package contains functions designed for processing and analyzing shipboard DAS data. This package was originally designed to handle [DAS data](https://repository.library.noaa.gov/view/noaa/3174) collected using WinCruz, the ship-based line-transect data collection software developed by the Southwest Fisheries Science Center. However, the `swfscDAS` package can be used by anyone who has collected DAS data that meets the format requirements described in the ['DAS data format'](#DAS-data-format) section below, for instance to process decades of available NOAA Fisheries DAS survey data. More generally, the package is intended to standardize and streamline basic DAS data processing. Functionality currently includes reading DAS data into a data frame, processing this data (extracting state and condition information for each DAS event), and summarizing sighting, effort, and comment information. Learn more in `vignette("swfscDAS")` diff --git a/man/swfscAirDAS-internals.Rd b/man/swfscAirDAS-internals.Rd index 75561cb..1ae2a4e 100644 --- a/man/swfscAirDAS-internals.Rd +++ b/man/swfscAirDAS-internals.Rd @@ -1,6 +1,7 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/das_chop_condition.R, R/das_chop_equallength.R, -% R/das_process.R, R/das_segdata.R, R/swfscDAS-internal.R +% Please edit documentation in R/das_chop_condition.R, +% R/das_chop_equallength.R, R/das_process.R, R/das_segdata.R, +% R/swfscDAS-internal.R \name{swfscAirDAS-internals} \alias{swfscAirDAS-internals} \alias{.chop_condition_eff} diff --git a/vignettes/swfscDAS.Rmd b/vignettes/swfscDAS.Rmd index bcea762..416bd5c 100644 --- a/vignettes/swfscDAS.Rmd +++ b/vignettes/swfscDAS.Rmd @@ -171,5 +171,6 @@ In addition, you can use `das_comments` to generate comment strings. This is par y.comm <- das_comments(y.proc) glimpse(select(y.comm, Event, line_num, comment_str)) -y.comm[str_detect(y.comm$comment_str, "gear"), ] #Could also use grepl() here +y.comm %>% + filter(str_detect(comment_str, "gear")) #Could also use grepl() here ``` From 3be5f3706f409444d0c792163a5fe9a5eef8ae5f Mon Sep 17 00:00:00 2001 From: Sam Woodman - NOAA Date: Mon, 20 Jul 2026 21:57:06 -0700 Subject: [PATCH 6/6] Fixes #16 - force as.Date to use tz=''. Correct docs --- NEWS.md | 4 +++- R/das_effort_strata.R | 4 ++-- R/das_process.R | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/NEWS.md b/NEWS.md index 87d3a8a..964265f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,8 +1,10 @@ # swfscDAS 0.6.5 (dev) +* Fix bug in `das_process` of incorrect OffsetGMT values, stemming from `as.Date` using 'UTC' tz by default (#16) + * Update link to NOAA Tech Memo describing DAS data; now (https://repository.library.noaa.gov/view/noaa/3174)[https://repository.library.noaa.gov/view/noaa/3174](#17) -* Fix documentation issues realted to upgrade to roxygen2 v8.0 +* Fix documentation issues related to upgrade to roxygen2 v8.0 # swfscDAS 0.6.4 diff --git a/R/das_effort_strata.R b/R/das_effort_strata.R index e90f72d..51fa988 100644 --- a/R/das_effort_strata.R +++ b/R/das_effort_strata.R @@ -36,13 +36,13 @@ das_effort_strata <- function(x, ...) UseMethod("das_effort_strata") #' @name das_effort_strata -#' @exportS3Method +#' @export das_effort_strata.data.frame <- function(x, ...) { das_effort_strata(as_das_df(x), ...) } #' @name das_effort_strata -#' @exportS3Method +#' @export das_effort_strata.das_df <- function(x, strata.files, ...) { # Check that none of the strata overlap strata.list <- lapply(strata.files, .das_pts2poly_vertices) #duplication, oh well diff --git a/R/das_process.R b/R/das_process.R index 96b652c..c69b2ef 100644 --- a/R/das_process.R +++ b/R/das_process.R @@ -251,7 +251,7 @@ das_process.das_dfr <- function(x, days.gap = 20, reset.event = TRUE, ### Extract GMT Offsets for dates + cruise numbers x.offset <- x %>% filter(.data$Event == "B") %>% - mutate(Date = as.Date(.data$DateTime), + mutate(Date = as.Date(.data$DateTime, tz = ""), Cruise = as.numeric(.data$Data1), OffsetGMT = as.integer(.data$Data3)) %>% select("Date", "Cruise", "OffsetGMT") %>% @@ -452,7 +452,7 @@ das_process.das_dfr <- function(x, days.gap = 20, reset.event = TRUE, ) data.frame(x, tmp, stringsAsFactors = FALSE) %>% - mutate(Date = as.Date(.data$DateTime)) %>% + mutate(Date = as.Date(.data$DateTime, tz = "")) %>% left_join(x.offset, by = c("Cruise", "Date")) %>% select(!!cols.tokeep) %>% as_das_df()