Skip to content

Commit

Permalink
Merge branch 'dev' into dev-no-tibble
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisholbrook authored Aug 15, 2024
2 parents c7fc9f2 + d4d106f commit 8c54fd4
Show file tree
Hide file tree
Showing 63 changed files with 402 additions and 201 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/style.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
shell: Rscript {0}

- name: Cache styler
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: ${{ steps.styler-location.outputs.location }}
key: ${{ runner.os }}-styler-${{ github.sha }}
Expand Down
3 changes: 1 addition & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ Imports:
readxl,
sf,
sp,
units,
zip
Suggests:
gganimate,
Expand All @@ -48,7 +47,7 @@ Authors@R: c(
License: GPL-2
LazyLoad: yes
LazyData: true
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
VignetteBuilder: knitr
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
Expand Down
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ importFrom(graphics,par)
importFrom(graphics,points)
importFrom(graphics,symbols)
importFrom(graphics,text)
importFrom(lubridate,parse_date_time)
importFrom(lubridate,fast_strptime)
importFrom(stats,approx)
importFrom(stats,dnorm)
importFrom(stats,ecdf)
Expand Down
24 changes: 12 additions & 12 deletions R/extdata.r
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#'
#' @section Filename: walleye_detections.zip
#'
#' @usage
#' system.file("extdata", "walleye_detections.zip", package="glatos")
#' @examples
#' system.file("extdata", "walleye_detections.zip", package = "glatos")
#'
#' @author Todd Hayden
#'
Expand Down Expand Up @@ -37,8 +37,8 @@ NULL
#'
#' @section Filename: SMRSL_GLATOS_20140828.xlsm
#'
#' @usage
#' system.file("extdata", "SMRSL_GLATOS_20140828.xlsm", package="glatos")
#' @examples
#' system.file("extdata", "SMRSL_GLATOS_20140828.xlsm", package = "glatos")
#'
#' @author Chris Holbrook
#'
Expand All @@ -53,12 +53,12 @@ NULL
#'
#' @format Folder contains 30 sequentially labeled .png image files
#'
#' @name video images
#' @name video-images
#'
#' @section Filename: frames
#'
#' @usage
#' system.file("extdata", "frames", package="glatos")
#' @examples
#' system.file("extdata", "frames", package = "glatos")
#'
#' @author Todd Hayden
#'
Expand All @@ -77,8 +77,8 @@ NULL
#'
#' @section Filename: shoreline.zip
#'
#' @usage
#' system.file("extdata", "shoreline.zip", package="glatos")
#' @examples
#' system.file("extdata", "shoreline.zip", package = "glatos")
#'
#' @author Todd Hayden
#'
Expand All @@ -95,7 +95,7 @@ NULL
#'
#' @section Filename: otn_aat_animals.csv
#'
#' @usage
#' @examples
#' system.file("extdata", "otn_aat_animals.csv", package = "glatos")
#'
#' @source Ryan Gosse, Ocean Tracking Network
Expand All @@ -111,7 +111,7 @@ NULL
#'
#' @section Filename: otn_aat_receivers.csv
#'
#' @usage
#' @examples
#' system.file("extdata", "otn_aat_receivers.csv", package = "glatos")
#'
#' @source Ryan Gosse, Ocean Tracking Network
Expand All @@ -127,7 +127,7 @@ NULL
#'
#' @section Filename: otn_aat_tag_releases.csv
#'
#' @usage
#' @examples
#' system.file("extdata", "otn_aat_tag_releases.csv", package = "glatos")
#'
#' @source Ryan Gosse, Ocean Tracking Network
Expand Down
7 changes: 7 additions & 0 deletions R/load-prepare_deploy_sheet.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@
#' @export

prepare_deploy_sheet <- function(path, header_line = 5, sheet_name = 1, combine_arr_stn = TRUE) {
## Declare global variables for NSE & R CMD check
DEPLOY_LAT <- DEPLOY_LONG <- INS_MODEL_NO <-
`DEPLOY_DATE_TIME (yyyy-mm-ddThh:mm:ss)` <-
`RECOVER_DATE_TIME (yyyy-mm-ddThh:mm:ss)` <- STATION_NO <-
OTN_ARRAY <- station <- ins_model_no <- deploy_lat <- deploy_long <-
deploy_date_time <- recover_date_time <- NULL

deploy_sheet <- readxl::read_excel(path,
sheet = sheet_name,
skip = header_line - 1,
Expand Down
4 changes: 4 additions & 0 deletions R/load-prepare_tag_sheet.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
#' @export

prepare_tag_sheet <- function(path, header_line = 5, sheet_name = 2) {
## Declare global variables for NSE & R CMD check
TAG_CODE_SPACE <- TAG_ID_CODE <- EST_TAG_LIFE <- UTC_RELEASE_DATE_TIME <-
SEX <- RELEASE_LATITUDE <- RELEASE_LONGITUDE <- SCIENTIFIC_NAME <- NULL

tag_sheet <- readxl::read_excel(path, sheet = sheet_name, skip = header_line - 1)
tag_sheet <- tag_sheet %>% dplyr::mutate(
transmitter_id = paste(TAG_CODE_SPACE, TAG_ID_CODE, sep = "-"),
Expand Down
15 changes: 6 additions & 9 deletions R/load-read_glatos_detections.r
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
#' never need to set this argument (`NULL` should work).
#'
#' @details Data are loaded using [fread][data.table::fread] and timestamps are
#' coerced to POSIXct using [fastPOSIXct][fasttime::fastPOSIXct]. All times must
#' be in UTC timezone per GLATOS standard.
#' coerced to POSIXct using [fast_strptime][lubridate::fast_strptime]. All times
#' must be in UTC timezone per GLATOS standard.
#'
#' @details Column `animal_id` is considered a required column by many other
#' functions in this package, so it will be created if any records are `NULL`.
Expand All @@ -40,7 +40,7 @@
#'
#' det <- read_glatos_detections(det_file)
#'
#' @importFrom lubridate parse_date_time
#' @importFrom lubridate fast_strptime
#'
#' @export
read_glatos_detections <- function(det_file, version = NULL) {
Expand Down Expand Up @@ -84,16 +84,13 @@ read_glatos_detections <- function(det_file, version = NULL) {
na.strings = c("", "NA")
)

# coerce timestamps to POSIXct; note that with fastPOSIXct raw
# timestamp must be in UTC; and tz argument sets the tzone attr only
options(lubridate.fasttime = TRUE)
# coerce timestamps to POSIXct
for (j in timestamp_cols) {
data.table::set(dtc,
j = glatos_detection_schema[[vversion]]$name[j],
value = lubridate::parse_date_time(
value = lubridate::fast_strptime(
dtc[[glatos_detection_schema[[vversion]]$name[j]]],
orders = "ymd HMS",
tz = "UTC"
format = "%Y-%m-%d %H:%M:%S", tz = "UTC", lt = FALSE
)
)
}
Expand Down
13 changes: 5 additions & 8 deletions R/load-read_glatos_receivers.r
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#' `"1.0"`. Any other values will trigger an error.
#'
#' @details Data are loaded using [fread][data.table::fread] and timestamps are
#' coerced to POSIXct using [fastPOSIXct][fasttime::fastPOSIXct]. All
#' coerced to POSIXct using [fast_strptime][lubridate::fast_strptime]. All
#' timestamps must be 'YYYY-MM-DD HH:MM' format and in UTC timezone per GLATOS
#' standard.
#'
Expand All @@ -36,7 +36,7 @@
#'
#' rcv <- read_glatos_receivers(rec_file)
#'
#' @importFrom lubridate parse_date_time
#' @importFrom lubridate fast_strptime
#'
#' @export
read_glatos_receivers <- function(rec_file, version = NULL) {
Expand Down Expand Up @@ -80,16 +80,13 @@ read_glatos_receivers <- function(rec_file, version = NULL) {
# read data
rec <- data.table::fread(rec_file, sep = ",", colClasses = col_classes)

# coerce timestamps to POSIXct; note that with fastPOSIXct raw
# timestamp must be in UTC; and tz argument sets the tzone attr only
options(lubridate.fasttime = TRUE)
# coerce timestamps to POSIXct
for (j in timestamp_cols) {
data.table::set(rec,
j = glatos_receivers_schema[[ver_txt]]$name[j],
value = lubridate::parse_date_time(
value = lubridate::fast_strptime(
rec[[glatos_receivers_schema[[ver_txt]]$name[j]]],
orders = "ymd HMS",
tz = "UTC"
format = "%Y-%m-%d %H:%M:%S", tz = "UTC", lt = FALSE
)
)
}
Expand Down
9 changes: 6 additions & 3 deletions R/load-read_otn_deployments.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#'
#' @details
#' Data are loaded using [data.table::fread()] package and timestamps
#' are coerced to POSIXct using the [fasttime::fastPOSIXct()]. All
#' are coerced to POSIXct using [lubridate::fast_strptime()]. All
#' times must be in UTC timezone per GLATOS standard.
#'
#' @details
Expand All @@ -39,7 +39,7 @@
#' dep <- read_otn_deployments(deployment_file)
#' }
#'
#' @importFrom lubridate parse_date_time
#' @importFrom lubridate fast_strptime
#' @importFrom dplyr mutate
#' @export
read_otn_deployments <- function(deployment_file,
Expand Down Expand Up @@ -73,7 +73,10 @@ read_otn_deployments <- function(deployment_file,
for (j in timestamp_cols) {
data.table::set(dtc,
j = otn_deployments_schema$name[j],
value = lubridate::parse_date_time(dtc[[otn_deployments_schema$name[j]]], orders = "ymd", tz = "UTC")
value = lubridate::fast_strptime(
dtc[[otn_deployments_schema$name[j]]],
format = "%Y-%m-%d %H:%M:%S", tz = "UTC", lt = FALSE
)
)
}
# coerce dates to date
Expand Down
13 changes: 7 additions & 6 deletions R/load-read_otn_detections.r
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#'
#' @details
#' Data are loaded using [data.table::fread()] package and timestamps
#' are coerced to POSIXct using the [fasttime::fastPOSIXct()]. All
#' are coerced to POSIXct using [lubridate::fast_strptime()]. All
#' times must be in UTC timezone per GLATOS standard.
#'
#' @details
Expand All @@ -28,7 +28,7 @@
#' )
#' det <- read_otn_detections(det_file)
#'
#' @importFrom lubridate parse_date_time
#' @importFrom lubridate fast_strptime
#'
#' @export
read_otn_detections <- function(det_file) {
Expand All @@ -53,13 +53,14 @@ read_otn_detections <- function(det_file) {
dtc$tagname <- dtc$fieldnumber
dtc$codespace <- purrr::map(dtc$fieldnumber, get_codemap)
}
# coerce timestamps to POSIXct; note that with fastPOSIXct raw
# timestamp must be in UTC; and tz argument sets the tzone attr only
options(lubridate.fasttime = TRUE)
# coerce timestamps to POSIXct
for (j in timestamp_cols) {
data.table::set(dtc,
j = otn_detection_schema$name[j],
value = lubridate::parse_date_time(dtc[[otn_detection_schema$name[j]]], orders = "ymd HMS", tz = "UTC")
value = lubridate::fast_strptime(
dtc[[otn_detection_schema$name[j]]],
format = "%Y-%m-%d %H:%M:%S", tz = "UTC", lt = FALSE
)
)
}
# coerce dates to date
Expand Down
9 changes: 5 additions & 4 deletions R/load-read_vdat_csv.r
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#' Read data from an Innovasea Fathom VDAT CSV file
#'
#' Read data from an Innovasea Fathom VDAT CSV file
#'
#' @param src A character string with path and name of an Innovasea VDAT CSV
#' detection file. If only file name is given, then the file must be located
#' in the working directory.
Expand Down Expand Up @@ -136,6 +134,9 @@ read_vdat_csv <- function(src,
return()
}

## Declare global variables for NSE & R CMD check
record_type <- NULL

# Identify vdat csv format version and vdat.exe version that created input csv
vdat_header <- data.table::fread(file = src, nrows = 1L, header = FALSE)

Expand Down Expand Up @@ -218,13 +219,13 @@ read_vdat_csv <- function(src,
keep.by = FALSE
)

data(vdat_csv_schema)
utils::data("vdat_csv_schema", envir = environment())

vdat_csv_schema <- vdat_csv_schema[[paste0("v", src_version$fathom_csv)]]


# Preallocate list; element = record type
vdat <- setNames(
vdat <- stats::setNames(
object = vector("list", length(vdat_list)),
nm = names(vdat_list)
)
Expand Down
11 changes: 8 additions & 3 deletions R/load-write_vdat_csv.r
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ write_vdat_csv <- function(vdat,
out_file = NULL,
output_format = "csv.fathom",
include_empty = FALSE) {
## Declare global variables for NSE & R CMD check
record_type <- dt2 <- `Device Time (UTC)` <- `Time Correction (s)` <-
`Ambient (deg C)` <- `Ambient Min (deg C)` <- `Ambient Max (deg C)` <-
`Ambient Mean (deg C)` <- `Internal (deg C)` <- ..txt_cols <- txt <- NULL

# Check input class
if (!inherits(vdat, "vdat_list")) {
stop(
Expand Down Expand Up @@ -107,7 +112,7 @@ write_vdat_csv <- function(vdat,
if (out_file_type == "dir") {
out_file_name <- gsub("\\.vrl$|\\.vdat$",
out_file_ext,
tail(vdat$DATA_SOURCE_FILE$`File Name`, 1),
utils::tail(vdat$DATA_SOURCE_FILE$`File Name`, 1),
ignore.case = TRUE
)

Expand Down Expand Up @@ -142,12 +147,12 @@ write_vdat_csv <- function(vdat,

# Compress each list element into a character vector

vdat_lines_body <- setNames(
vdat_lines_body <- stats::setNames(
object = vector("list", length(record_types)),
record_types
)

vdat_lines_header <- setNames(
vdat_lines_header <- stats::setNames(
object = vector("list", length(record_types)),
record_types
)
Expand Down
9 changes: 6 additions & 3 deletions R/package-glatos.r
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@
#'
#' \item{[real_sensor_values]}{ Converts 'raw' transmitter sensor (e.g.,
#' depth, temperature) to 'real'-scale values (e.g., depth in meters) using
#' transmitter specification data (e.g., from read\_vemco\_tag\_specs).} }
#' transmitter specification data (e.g., from [read_vemco_tag_specs]).} }
#'
#' @section Filtering and summarizing: \describe{
#' \item{[min_lag]}{
#' Facilitates identification and removal of false positive detections by
#' calculating the minimum time interval (min\_lag) between successive
#' calculating the minimum time interval (min_lag) between successive
#' detections.}
#'
#' \item{[false_detections]}{ Removes potential false positive detections
Expand Down Expand Up @@ -124,7 +124,10 @@
#' @importFrom grDevices bmp colorRampPalette dev.new dev.off jpeg png rainbow
#' tiff
#' @importFrom dplyr %>%
globalVariables(".") # to avoid R CMD check note
"_PACKAGE"

# avoid R CMD check note
globalVariables(".")

# package startup message
.onAttach <- function(libname, pkgname) {
Expand Down
4 changes: 4 additions & 0 deletions R/proc-min_lag.r
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@
#' @export

min_lag <- function(det) {
## Declare global variables for NSE & R CMD check
ord <- transmitter_codespace <- transmitter_id <- receiver_sn <-
detection_timestamp_utc <- NULL

# coerce to data.table
dtc <- data.table::as.data.table(det)

Expand Down
4 changes: 4 additions & 0 deletions R/proc-real_sensor_values.r
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@
#' @export

real_sensor_values <- function(det, tag_specs) {
## Declare global variables for NSE & R CMD check
ord <- transmitter_codespace <- transmitter_id <- code_space <- id_code <-
sensor_value_real <- sensor_intercept <- sensor_value <- sensor_slope <- NULL

# coerce to data.table
dtc <- data.table::as.data.table(det)

Expand Down
Loading

0 comments on commit 8c54fd4

Please sign in to comment.