Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix checks: "R code for possible problems", "Rd files"/"metadata"/"cross-references"/"code/documentation mismatches"; kml_to_csv bug/tests #228

Merged
merged 57 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
8b58649
declare globals for residence_index; explicit use of dplyr::across
mhpob May 11, 2024
01227c1
explicitly use utils::head/tails to avoid abiguity warning
mhpob May 11, 2024
75f4d06
Declare globals: convert_glatos_to_att
mhpob May 11, 2024
ecd5140
Declare globals for convert_otn_erddap_to_att
mhpob May 11, 2024
62a4f15
Declare globals for convert_otn_to_att
mhpob May 11, 2024
f3573df
explicit use of utils::tail
mhpob May 11, 2024
a0116dd
define globals: detect_transmissions
mhpob May 11, 2024
833fed3
call great_lakes_polygon without using global variable
mhpob May 11, 2024
1b18373
declare globals: interpolate_path
mhpob May 11, 2024
032b17c
wrong argument: kml_file -> filePath
mhpob May 11, 2024
b92fa5e
declare globals: kml_workbook
mhpob May 11, 2024
93ff7d7
declare globals: make_frames
mhpob May 11, 2024
78a837d
declare globals: min_lag
mhpob May 11, 2024
13f1252
declare globals: prepare_deploy_sheet
mhpob May 11, 2024
b6cff76
declare globals: prepare_tag_sheet
mhpob May 11, 2024
6d54ac3
Merge branch 'dev' into dev-declare-globals
mhpob May 11, 2024
66b33f8
Update documentation
mhpob May 11, 2024
a7295d6
declare globals; call vdat_csv_schema without global var; call stats:…
mhpob May 11, 2024
f553dc0
Merge branch 'dev-declare-globals' of https://github.com/mhpob/glatos…
mhpob May 11, 2024
1fb9fc7
Declare globals: real_sensor_values
mhpob May 11, 2024
f63a2d9
declare globals: REI
mhpob May 11, 2024
e27d229
declare globals: summarize_detections
mhpob May 11, 2024
0fa0d26
declare globals: transmit_along_path
mhpob May 11, 2024
c9ff4d4
declare globals: vdat_convert
mhpob May 11, 2024
4478bdc
declare globals: vue_convert
mhpob May 11, 2024
110b910
declare globals: write_vdat_csv; explicitly call stats::setNames and …
mhpob May 11, 2024
709f0f2
Style code (GHA)
mhpob May 11, 2024
67fa300
Add kml_to_csv test
mhpob May 11, 2024
e32cdce
Merge branch 'dev-declare-globals' of https://github.com/mhpob/glatos…
mhpob May 11, 2024
7564865
Style code (GHA)
mhpob May 11, 2024
e625332
fix partial match
mhpob May 11, 2024
1a9e7dc
call utils::data
mhpob May 11, 2024
484d4f5
load data into function's environment rather than global user environ…
mhpob May 11, 2024
802d3c7
fix introduced utils::data bug
mhpob May 11, 2024
f885ff2
Style code (GHA)
mhpob May 11, 2024
d8073d9
fix introduced utils::data bug
mhpob May 11, 2024
d9f5651
Stylr
mhpob May 11, 2024
ab22ef9
Style code (GHA)
mhpob May 11, 2024
4e3b8ef
missed a utils
mhpob May 11, 2024
31aa760
expect_identical to expect_equal to avoid floating point issues
mhpob May 11, 2024
3c66ebf
Merge branch 'dev-declare-globals' of https://github.com/mhpob/glatos…
mhpob May 11, 2024
2adc262
Update documentation
mhpob May 11, 2024
edc1017
Fix forgotten NULL
mhpob May 13, 2024
faf6fac
Style code (GHA)
mhpob May 13, 2024
047f150
fix latex escape and invalid alias tagging
mhpob May 13, 2024
bcdd387
fix latex escape
mhpob May 13, 2024
1f47093
fix misspecified itemize list
mhpob May 13, 2024
58aea3b
Merge branch 'dev-declare-globals' of https://github.com/mhpob/glatos…
mhpob May 13, 2024
81a0b81
fix misspecified itemize list
mhpob May 13, 2024
f4a21c8
fix rd link
mhpob May 13, 2024
642a77c
fix missing link by rm
mhpob May 13, 2024
07ff39b
backtick so roxygen doesn interpret boxed code as a link
mhpob May 13, 2024
d520fc7
useage to example
mhpob May 13, 2024
9735e5e
Style code (GHA)
mhpob May 13, 2024
f2e4173
add back global dot var
mhpob May 13, 2024
0638483
example -> exampleS
mhpob May 13, 2024
95529b8
Update documentation
mhpob May 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 @@ -123,7 +123,10 @@
#' txtProgressBar unzip write.csv write.table zip
#' @importFrom grDevices bmp colorRampPalette dev.new dev.off jpeg png rainbow
#' tiff
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
12 changes: 6 additions & 6 deletions R/sim-crw_in_polygon.r
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
#' are also accepted); \cr *OR* \cr A polygon defined as data frame or
#' matrix with numeric columns x and y.
#'
#' @param theta A 2-element numeric vector with turn angle parameters (theta[1]
#' = mean; theta[2] = sd), in degrees, from normal distribution.
#' @param theta A 2-element numeric vector with turn angle parameters (`theta[1]`
#' = mean; `theta[2]` = sd), in degrees, from normal distribution.
#'
#' @param stepLen A numeric scalar with total distance moved in each step, in
#' meters.
#'
#' @param initPos A 2-element numeric vector with initial position
#' (initPos[1]=x, initPos[2]=y) in same coordinate reference system as
#' (`initPos[1]`=x, `initPos[2]`=y) in same coordinate reference system as
#' `polyg`.
#'
#' @param initHeading A numeric scalar with initial heading in degrees. E.g., 0
Expand Down Expand Up @@ -242,7 +242,7 @@ crw_in_polygon <- function(polyg, theta = c(0, 10), stepLen = 100,
}

# Close polyg if needed (first and last point must be same)
if (!identical(polyg[1, ], tail(polyg, 1))) polyg <- rbind(polyg, polyg[1, ])
if (!identical(polyg[1, ], utils::tail(polyg, 1))) polyg <- rbind(polyg, polyg[1, ])

# Make sf object
polyg_sf <- sf::st_polygon(list(as.matrix(polyg[c("x", "y")])))
Expand Down Expand Up @@ -429,8 +429,8 @@ check_cross_boundary <- function(path, boundary, EPSG) {
# Make line segment objects of sequential point-pairs in path

segs_mat <- cbind(
head(path, -1),
tail(path, -1)
utils::head(path, -1),
utils::tail(path, -1)
)

in_poly <-
Expand Down
3 changes: 3 additions & 0 deletions R/sim-detect_transmissions.r
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@ detect_transmissions <- function(trnsLoc = NA,
inputCRS = NA,
sp_out = TRUE,
show_progress = TRUE) {
## Declare global variables for NSE & R CMD check
trns_x <- trns_y <- NULL

# Check input class - trnsLoc
if (!inherits(trnsLoc, c("data.frame", "sf", "sfc", "SpatialPointsDataFrame"))) {
stop(
Expand Down
3 changes: 3 additions & 0 deletions R/sim-transmit_along_path.r
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ transmit_along_path <- function(path = NA,
),
pathCRS = NA,
sp_out = TRUE) {
## Declare global variables for NSE & R CMD check
cumdistm <- NULL

# Check input class
if (!inherits(path, c("data.frame", "sf", "sfc", "SpatialPointsDataFrame"))) {
stop(
Expand Down
6 changes: 3 additions & 3 deletions R/simutil-crw.r
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
#' drawn from a normal distribution.
#'
#' @param theta A 2-element numeric vector with turn angle parameters
#' (theta[1] = mean; theta[2] = sd) from normal distribution.
#' (`theta[1]` = mean; `theta[2]` = sd) from normal distribution.
#'
#' @param stepLen A numeric scalar with total distance moved in each step.
#'
#' @param initPos A 2-element numeric vector with nital position (initPos[1]=x,
#' initPos[2]=y).
#' @param initPos A 2-element numeric vector with nital position (`initPos[1]`=x,
#' `initPos[2]`=y).
#'
#' @param initHeading A numeric scalar with initial heading in degrees.
#'
Expand Down
4 changes: 4 additions & 0 deletions R/summ-receiver_efficiency.r
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@
#' @export

REI <- function(detections, deployments) {
## Declare global variables for NSE & R CMD check
recover_date_time <- last_download <- station <- days_deployed <- deploy_lat <-
deploy_long <- animal_id <- common_name_e <- detection_timestamp_utc <- NULL

# Check for proper columns
required_deployment_columns <- c("station", "deploy_date_time", "recover_date_time")
required_detection_columns <- c("station", "common_name_e", "animal_id", "detection_timestamp_utc")
Expand Down
15 changes: 13 additions & 2 deletions R/summ-residence_index.r
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ residence_index <- function(
detections, calculation_method = "kessel",
locations = NULL, group_col = "animal_id", time_interval_size = "1 day",
groupwise_total = TRUE) {
# Declare global variables for R CMD check
location <- mean_latitude <- mean_longitude <- days_detected <-
total_days <- NULL


# set to NULL if NA
if (!is.null(group_col)) if (is.na(group_col)) group_col <- NULL
if (!is.null(locations)) if (all(is.na(locations))) locations <- NULL
Expand Down Expand Up @@ -237,7 +242,7 @@ residence_index <- function(
# numerator
group_cols <- c("location", group_col)

detections <- dplyr::group_by(detections, across(group_cols))
detections <- dplyr::group_by(detections, dplyr::across(group_cols))

ri <- dplyr::do(
detections,
Expand All @@ -263,7 +268,7 @@ residence_index <- function(
time_interval_size
)
} else {
detections <- dplyr::group_by(detections, across(group_col))
detections <- dplyr::group_by(detections, dplyr::across(group_col))
ri <- dplyr::left_join(ri,
dplyr::do(
detections,
Expand Down Expand Up @@ -365,6 +370,9 @@ total_diff_days <- function(detections) {
#'
#' @importFrom dplyr mutate
aggregate_total_with_overlap <- function(detections) {
# Declare global variables for R CMD check
last_detection <- first_detection <- NULL

detections <- mutate(detections, timedelta = as.double(difftime(last_detection, first_detection, units = "secs")))
detections <- mutate(detections, timedelta = dplyr::recode(detections$timedelta, `0` = 1))
total <- as.double(sum(detections$timedelta)) / 86400.0
Expand All @@ -382,6 +390,9 @@ aggregate_total_with_overlap <- function(detections) {
#'
#' @importFrom data.table foverlaps
aggregate_total_no_overlap <- function(detections) {
# Declare global variables for R CMD check
t1 <- t2 <- first_detection <- last_detection <- xid <- yid <- tdiff <- NULL

# extract intervals, rename
ints <- data.table::as.data.table(detections)[, .(
t1 = first_detection,
Expand Down
5 changes: 5 additions & 0 deletions R/summ-summarize_detections.r
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@
summarize_detections <- function(det, location_col = "glatos_array",
receiver_locs = NULL, animals = NULL,
summ_type = "animal") {
## Declare global variables for NSE & R CMD check
deploy_lat <- deploy_long <- detection_timestamp_utc <- num_fish <- animal_id <-
num_locs <- num_dets <- NULL


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

Expand Down
4 changes: 2 additions & 2 deletions R/testdata.r
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#'
#' @section Filename: higgins_lake_transition.rds
#'
#' @usage
#' @examples
#' system.file("testdata", "higgins_lake_transition.rds", package = "glatos")
#'
#' @author Chris Holbrook
Expand All @@ -29,7 +29,7 @@ NULL
#'
#' @section Filename: flynn_island_transition.rds
#'
#' @usage
#' @examples
#' system.file("testdata", "flynn_island_transition.rds", package = "glatos")
#'
#' @author Chris Holbrook
Expand Down
5 changes: 5 additions & 0 deletions R/util-convert_glatos_to_att.r
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@

convert_glatos_to_att <- function(detectionObj, receiverObj,
crs = sp::CRS("+init=epsg:4326")) {
## Declare global variables for R CMD check
Sex <- glatos_array <- station_no <- deploy_lat <- deploy_long <-
station <- dummy <- ins_model_no <- ins_serial_no <-
deploy_date_time <- recover_date_time <- detection_timestamp_utc <- NULL

transmitters <-
if (all(grepl("-", detectionObj$transmitter_id, fixed = TRUE))) {
detectionObj$transmitter_id
Expand Down
Loading