diff --git a/NAMESPACE b/NAMESPACE index 94fcaf2d..8fa1007b 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -99,7 +99,7 @@ importFrom(graphics,par) importFrom(graphics,points) importFrom(graphics,symbols) importFrom(graphics,text) -importFrom(lubridate,parse_date_time) +importFrom(lubridate,fast_strptime) importFrom(magrittr,"%>%") importFrom(stats,approx) importFrom(stats,dnorm) diff --git a/R/load-read_glatos_detections.r b/R/load-read_glatos_detections.r index a4b3d9f1..6f555bd1 100644 --- a/R/load-read_glatos_detections.r +++ b/R/load-read_glatos_detections.r @@ -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`. @@ -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) { @@ -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 ) ) } diff --git a/R/load-read_glatos_receivers.r b/R/load-read_glatos_receivers.r index 5b45e328..b0309865 100644 --- a/R/load-read_glatos_receivers.r +++ b/R/load-read_glatos_receivers.r @@ -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. #' @@ -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) { @@ -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 ) ) } diff --git a/R/load-read_otn_deployments.R b/R/load-read_otn_deployments.R index 5f4aa9d7..4bc6d150 100644 --- a/R/load-read_otn_deployments.R +++ b/R/load-read_otn_deployments.R @@ -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 @@ -39,7 +39,7 @@ #' dep <- read_otn_deployments(deployment_file) #' } #' -#' @importFrom lubridate parse_date_time +#' @importFrom lubridate fast_strptime #' @importFrom tidyr extract #' @importFrom dplyr mutate #' @importFrom magrittr "%>%" @@ -60,8 +60,7 @@ read_otn_deployments <- function(deployment_file, 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 + # coerce timestamps to POSIXct dtc <- dtc %>% tidyr::extract(deploy_date_col, into = "deploy_date", regex = "(\\d+-\\d+-\\d+)") dtc <- dtc %>% tidyr::extract(recovery_date_col, into = "recovery_date", regex = "(\\d+-\\d+-\\d+)") dtc <- dtc %>% tidyr::extract(last_download_col, into = "last_download", regex = "(\\d+-\\d+-\\d+)") @@ -70,7 +69,9 @@ 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 diff --git a/R/load-read_otn_detections.r b/R/load-read_otn_detections.r index 7f3191a4..898bb339 100644 --- a/R/load-read_otn_detections.r +++ b/R/load-read_otn_detections.r @@ -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 @@ -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) { @@ -38,11 +38,11 @@ read_otn_detections <- function(det_file) { timestamp_cols <- which(col_classes == "POSIXct") date_cols <- which(col_classes == "Date") col_classes[c(timestamp_cols, date_cols)] <- "character" - + # read data, suppressWarnings because some columns could be missing dtc <- suppressWarnings(data.table::fread(det_file, - sep = ",", colClasses = col_classes, - na.strings = c("", "NA") + sep = ",", colClasses = col_classes, + na.strings = c("", "NA") )) # This check is for non-matched detection extracts. They are missing some required columns, this attempts to create them. # More info on OTN detection extracts here: https://members.oceantrack.org/data/otn-detection-extract-documentation-matched-to-animals @@ -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") + j = otn_detection_schema$name[j], + 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 diff --git a/man/read_glatos_detections.Rd b/man/read_glatos_detections.Rd index 3dd8270b..542d547c 100644 --- a/man/read_glatos_detections.Rd +++ b/man/read_glatos_detections.Rd @@ -28,8 +28,8 @@ a data.frame of class \code{glatos_detections}. } \details{ Data are loaded using \link[data.table:fread]{fread} and timestamps are -coerced to POSIXct using \link[fasttime:fastPOSIXct]{fastPOSIXct}. All times must -be in UTC timezone per GLATOS standard. +coerced to POSIXct using \link[lubridate:parse_date_time]{fast_strptime}. All times +must be in UTC timezone per GLATOS standard. Column \code{animal_id} is considered a required column by many other functions in this package, so it will be created if any records are \code{NULL}. diff --git a/man/read_glatos_receivers.Rd b/man/read_glatos_receivers.Rd index 7a442ddc..13fac121 100644 --- a/man/read_glatos_receivers.Rd +++ b/man/read_glatos_receivers.Rd @@ -27,7 +27,7 @@ data.frame of class \code{glatos_receivers}. } \details{ Data are loaded using \link[data.table:fread]{fread} and timestamps are -coerced to POSIXct using \link[fasttime:fastPOSIXct]{fastPOSIXct}. All +coerced to POSIXct using \link[lubridate:parse_date_time]{fast_strptime}. All timestamps must be 'YYYY-MM-DD HH:MM' format and in UTC timezone per GLATOS standard. } diff --git a/man/read_otn_deployments.Rd b/man/read_otn_deployments.Rd index ead0dbfb..3b087467 100644 --- a/man/read_otn_deployments.Rd +++ b/man/read_otn_deployments.Rd @@ -35,7 +35,7 @@ a data.frame of class \code{glatos_receivers}. } \details{ Data are loaded using \code{\link[data.table:fread]{data.table::fread()}} package and timestamps -are coerced to POSIXct using the \code{\link[fasttime:fastPOSIXct]{fasttime::fastPOSIXct()}}. All +are coerced to POSIXct using \code{\link[lubridate:parse_date_time]{lubridate::fast_strptime()}}. All times must be in UTC timezone per GLATOS standard. Column names are changed to match GLATOS standard columns when possible. diff --git a/man/read_otn_detections.Rd b/man/read_otn_detections.Rd index 85325692..349b349c 100644 --- a/man/read_otn_detections.Rd +++ b/man/read_otn_detections.Rd @@ -21,7 +21,7 @@ a data.frame of class \code{glatos_detections}. } \details{ Data are loaded using \code{\link[data.table:fread]{data.table::fread()}} package and timestamps -are coerced to POSIXct using the \code{\link[fasttime:fastPOSIXct]{fasttime::fastPOSIXct()}}. All +are coerced to POSIXct using \code{\link[lubridate:parse_date_time]{lubridate::fast_strptime()}}. All times must be in UTC timezone per GLATOS standard. Column names are changed to match GLATOS standard columns when possible.