Skip to content

Commit

Permalink
Merge pull request #214 from mhpob/dev-internal-func-warnings
Browse files Browse the repository at this point in the history
Pass R CMD check with no errors
  • Loading branch information
jdpye authored Feb 16, 2024
2 parents 13c5709 + 5c8a9e4 commit a5f0b1b
Show file tree
Hide file tree
Showing 33 changed files with 722 additions and 632 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
^README\.Rmd$
^README-.*\.png$
^\.github$
^R/util-intern_pkg_man\.r$
1 change: 1 addition & 0 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,4 @@ jobs:
- uses: r-lib/actions/check-r-package@v2
with:
upload-snapshots: true
error-on: '"error"'
11 changes: 6 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,32 @@ Imports:
data.table,
dplyr,
fasterize,
fasttime,
gdalUtilities,
geodist,
gdistance,
geosphere,
jsonlite,
knitr,
lubridate,
magrittr,
methods,
plotrix,
purrr,
raster,
readxl,
rmarkdown,
sf,
sp,
tibble,
tidyr,
units,
zip
Suggests:
gganimate,
gifski,
knitr,
methods,
png,
testthat (>= 3.0.0),
rmarkdown,
terra,
testthat (>= 3.0.0),
tint
URL: https://github.com/ocean-tracking-network/glatos
BugReports: https://github.com/ocean-tracking-network/glatos/issues
Expand Down
14 changes: 9 additions & 5 deletions R/class-glatos_animals.r
Original file line number Diff line number Diff line change
Expand Up @@ -71,24 +71,28 @@
#' ga_tbl <- as_glatos_animals(x_tbl)
#'
#'
#' # All below will error as invalid
#'
#' # data.frame input; missing column name
#' library(dplyr) # for rename
#' x2 <- rename(x,
#' fish_name = animal_id,
#' release_timestamp = utc_release_date_time
#' )
#'
#' ga2 <- as_glatos_animals(x2)
#'
#' try(
#' ga2 <- as_glatos_animals(x2)
#' )
#'
#' # data.grame input; wrong column class
#' # data.frame input; wrong column class
#' x3 <- mutate(x,
#' animal_id = as.integer(animal_id),
#' utc_release_date_time = as.character(utc_release_date_time)
#' )
#'
#' ga3 <- as_glatos_animals(x3)
#'
#' try(
#' ga3 <- as_glatos_animals(x3)
#' )
#'
#' # Validation and checking
#'
Expand Down
12 changes: 8 additions & 4 deletions R/class-glatos_detections.r
Original file line number Diff line number Diff line change
Expand Up @@ -73,24 +73,28 @@
#' gd_tbl <- as_glatos_detections(x_tbl)
#'
#'
#' # All below will error as invalid
#'
#' # data.frame input; missing column name
#' library(dplyr) # for rename
#' x2 <- rename(x,
#' fish_id = animal_id,
#' det_date_time = detection_timestamp_utc
#' )
#'
#' gd2 <- as_glatos_detections(x2)
#'
#' try(
#' gd2 <- as_glatos_detections(x2)
#' )
#'
#' # data.frame input; wrong column class
#' x3 <- mutate(x,
#' animal_id = as.integer(animal_id),
#' detection_timestamp_utc = as.character(detection_timestamp_utc)
#' )
#'
#' gr3 <- as_glatos_detections(x3)
#'
#' try(
#' gr3 <- as_glatos_detections(x3)
#' )
#'
#' # Validation and checking
#'
Expand Down
11 changes: 7 additions & 4 deletions R/class-glatos_receivers.r
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
#'
#' gr_tbl <- as_glatos_receivers(x_tbl)
#'
#' # All below will error as invalid
#'
#' # data.frame input; missing column name
#' library(dplyr) # for rename
Expand All @@ -94,17 +95,19 @@
#' deploy_timestamp = deploy_date_time
#' )
#'
#' gr2 <- as_glatos_receivers(x2)
#'
#' try(
#' gr2 <- as_glatos_receivers(x2)
#' )
#'
#' # data.frame input; wrong column class
#' x3 <- mutate(x,
#' ins_serial_no = as.integer(ins_serial_no),
#' deploy_date_time = as.character(deploy_date_time)
#' )
#'
#' gr3 <- as_glatos_receivers(x3)
#'
#' try(
#' gr3 <- as_glatos_receivers(x3)
#' )
#'
#' # Validation and checking
#'
Expand Down
22 changes: 11 additions & 11 deletions R/load-read_glatos_detections.r
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ read_glatos_detections <- function(det_file, version = NULL) {
# Identify detection file version
id_det_version <- function(det_file) {
det_col_names <- names(data.table::fread(det_file, nrows = 0))
if (all(glatos:::glatos_detection_schema$v1.4$name %in% det_col_names)) {
if (all(glatos_detection_schema$v1.4$name %in% det_col_names)) {
return("1.4")
} else if (all(glatos:::glatos_detection_schema$v1.3$name %in% det_col_names)) {
} else if (all(glatos_detection_schema$v1.3$name %in% det_col_names)) {
return("1.3")
} else {
stop("Detection file version could not be identified.")
Expand All @@ -65,15 +65,15 @@ read_glatos_detections <- function(det_file, version = NULL) {
if (is.null(version)) {
version <- id_det_version(det_file)
} else if (!(paste0("v", version) %in%
names(glatos:::glatos_detection_schema))) {
names(glatos_detection_schema))) {
stop(paste0("Detection file version ", version, " is not supported."))
}

#-Detections v1.3 or v1.4-----------------------------------------------------
if (version %in% c("1.3", "1.4")) {
vversion <- paste0("v", version)

col_classes <- glatos:::glatos_detection_schema[[vversion]]$type
col_classes <- glatos_detection_schema[[vversion]]$type
timestamp_cols <- which(col_classes == "POSIXct")
date_cols <- which(col_classes == "Date")
col_classes[c(timestamp_cols, date_cols)] <- "character"
Expand All @@ -89,9 +89,9 @@ read_glatos_detections <- function(det_file, version = NULL) {
options(lubridate.fasttime = TRUE)
for (j in timestamp_cols) {
data.table::set(dtc,
j = glatos:::glatos_detection_schema[[vversion]]$name[j],
j = glatos_detection_schema[[vversion]]$name[j],
value = lubridate::parse_date_time(
dtc[[glatos:::glatos_detection_schema[[vversion]]$name[j]]],
dtc[[glatos_detection_schema[[vversion]]$name[j]]],
orders = "ymd HMS",
tz = "UTC"
)
Expand All @@ -100,15 +100,15 @@ read_glatos_detections <- function(det_file, version = NULL) {
# coerce dates to date
for (j in date_cols) {
data.table::set(dtc,
j = glatos:::glatos_detection_schema[[vversion]]$name[j],
value = ifelse(dtc[[glatos:::glatos_detection_schema[[vversion]]$name[j]]] == "",
j = glatos_detection_schema[[vversion]]$name[j],
value = ifelse(dtc[[glatos_detection_schema[[vversion]]$name[j]]] == "",
NA,
dtc[[glatos:::glatos_detection_schema[[vversion]]$name[j]]]
dtc[[glatos_detection_schema[[vversion]]$name[j]]]
)
)
data.table::set(dtc,
j = glatos:::glatos_detection_schema[[vversion]]$name[j],
value = as.Date(dtc[[glatos:::glatos_detection_schema[[vversion]]$name[j]]])
j = glatos_detection_schema[[vversion]]$name[j],
value = as.Date(dtc[[glatos_detection_schema[[vversion]]$name[j]]])
)
}
}
Expand Down
8 changes: 4 additions & 4 deletions R/load-read_glatos_receivers.r
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ read_glatos_receivers <- function(rec_file, version = NULL) {
# Identify file version
id_file_version <- function(rec_file) {
col_names <- names(data.table::fread(rec_file, nrows = 0))
if (all(glatos:::glatos_receivers_schema$v1.1$name %in% col_names)) {
if (all(glatos_receivers_schema$v1.1$name %in% col_names)) {
return("1.1")
} else if (all(glatos:::glatos_receivers_schema$v1.0$name %in% col_names)) {
} else if (all(glatos_receivers_schema$v1.0$name %in% col_names)) {
return("1.0")
} else {
stop("Receiver location file version could not be identified.")
Expand All @@ -61,7 +61,7 @@ read_glatos_receivers <- function(rec_file, version = NULL) {
if (is.null(version)) {
version <- id_file_version(rec_file)
} else if (!(paste0("v", version) %in%
names(glatos:::glatos_receivers_schema))) {
names(glatos_receivers_schema))) {
stop(paste0(
"Receiver locations file version ", version,
" is not supported."
Expand All @@ -72,7 +72,7 @@ read_glatos_receivers <- function(rec_file, version = NULL) {
if (version %in% c("1.0", "1.1")) {
ver_txt <- paste0("v", version)

col_classes <- glatos:::glatos_receivers_schema[[ver_txt]]$type
col_classes <- glatos_receivers_schema[[ver_txt]]$type
timestamp_cols <- which(col_classes == "POSIXct")
date_cols <- which(col_classes == "Date")
col_classes[c(timestamp_cols, date_cols)] <- "character"
Expand Down
14 changes: 7 additions & 7 deletions R/load-read_glatos_workbook.r
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ read_glatos_workbook <- function(

# Identify workbook version (based on sheet names)
id_workbook_version <- function(wb_file, sheets) {
if (all(names(glatos:::glatos_workbook_schema$v1.3) %in% sheets)) {
if (all(names(glatos_workbook_schema$v1.3) %in% sheets)) {
return("1.3")
} else {
stop(paste0(
Expand All @@ -124,7 +124,7 @@ read_glatos_workbook <- function(
if (is.null(wb_version)) {
wb_version <- id_workbook_version(wb_file, sheets)
} else if (!(paste0("v", wb_version) %in%
names(glatos:::glatos_workbook_schema))) {
names(glatos_workbook_schema))) {
stop(paste0("Workbook version ", wb_version, " is not supported."))
}

Expand All @@ -134,7 +134,7 @@ read_glatos_workbook <- function(

#-Workbook v1.3--------------------------------------------------------------
if (wb_version == "1.3") {
wb[names(glatos:::glatos_workbook_schema$v1.3)] <- NA
wb[names(glatos_workbook_schema$v1.3)] <- NA

# Get project data
tmp <- tryCatch(
Expand Down Expand Up @@ -170,18 +170,18 @@ read_glatos_workbook <- function(
# Read all sheets except project
if (read_all) {
sheets_to_read <- sheets
extra_sheets <- setdiff(sheets, names(glatos:::glatos_workbook_schema[[
extra_sheets <- setdiff(sheets, names(glatos_workbook_schema[[
paste0("v", wb_version)
]]))
} else {
sheets_to_read <- names(glatos:::glatos_workbook_schema[[
sheets_to_read <- names(glatos_workbook_schema[[
paste0("v", wb_version)
]])
}
sheets_to_read <- setdiff(sheets_to_read, "project") # exclude project

for (i in 1:length(sheets_to_read)) {
schema_i <- glatos:::glatos_workbook_schema[[
schema_i <- glatos_workbook_schema[[
paste0("v", wb_version)
]][[sheets_to_read[i]]]

Expand Down Expand Up @@ -532,7 +532,7 @@ read_glatos_workbook <- function(
# assign classes
wb2$animals <- as_glatos_animals(wb2$animals)
wb2$receivers <- as_glatos_receivers(wb2$receivers)
wb2 <- glatos:::glatos_workbook(wb2)
wb2 <- glatos_workbook(wb2)

return(wb2)
}
2 changes: 2 additions & 0 deletions R/load-read_otn_deployments.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@
#' @author A. Nunes, \email{[email protected]}
#'
#' @examples
#' \dontrun{
#' # get path to example deployments file
#' deployment_file <- system.file("extdata", "hfx_deployments.csv",
#' package = "glatos"
#' )
#' dep <- read_otn_deployments(deployment_file)
#' }
#'
#' @importFrom lubridate parse_date_time
#' @importFrom tidyr extract
Expand Down
Loading

0 comments on commit a5f0b1b

Please sign in to comment.