Skip to content

Commit

Permalink
Merge pull request #228 from mhpob/dev-declare-globals
Browse files Browse the repository at this point in the history
Fix checks: "R code for possible problems", "Rd files"/"metadata"/"cross-references"/"code/documentation mismatches"; `kml_to_csv` bug/tests
  • Loading branch information
chrisholbrook authored Aug 14, 2024
2 parents e891deb + 95529b8 commit f9a65ca
Show file tree
Hide file tree
Showing 52 changed files with 369 additions and 165 deletions.
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

0 comments on commit f9a65ca

Please sign in to comment.