From 4b42a5a898af42f8ac70189ebf1e2a128a7a27ac Mon Sep 17 00:00:00 2001 From: wdwatkins Date: Tue, 26 Jul 2016 10:13:49 -0500 Subject: [PATCH 1/2] Fixed bug with new readr version --- R/importRDB1.r | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/R/importRDB1.r b/R/importRDB1.r index f222ad32..288d2d71 100644 --- a/R/importRDB1.r +++ b/R/importRDB1.r @@ -49,6 +49,11 @@ #' @importFrom readr problems #' @importFrom lubridate fast_strptime #' @importFrom lubridate parse_date_time +#' @importFrom lubridate seconds_to_period +#' @importFrom lubridate second +#' @importFrom lubridate minute +#' @importFrom lubridate hour +#' @import lubridate #' @examples #' siteNumber <- "02177000" #' startDate <- "2012-09-01" @@ -117,6 +122,11 @@ importRDB1 <- function(obs_url, asDateTime=TRUE, convertType = TRUE, tz=""){ if(convertType){ readr.data <- suppressWarnings(read_delim(doc, skip = (meta.rows+2),delim="\t",col_names = FALSE)) + #defaults to time in seconds in readr 0.2.2.9?? + if(data.class(readr.data$X4)=="hms"){ + td <- seconds_to_period(readr.data$X4[!is.na(readr.data$X4)]) + readr.data$X4[!is.na(readr.data$X4)] <- sprintf('%02d:%02d:%02d', hour(td), minute(td), second(td)) + } } else { readr.data <- read_delim(doc, skip = (meta.rows+2),delim="\t",col_names = FALSE, col_types = cols(.default = "c")) } @@ -167,7 +177,7 @@ importRDB1 <- function(obs_url, asDateTime=TRUE, convertType = TRUE, tz=""){ if(all(c(paste0(i,"_dt"),paste0(i,"_tm")) %in% header.names)){ varname <- paste0(i,"_dateTime") - varval <- as.POSIXct(fast_strptime(paste(readr.data[,paste0(i,"_dt")],readr.data[,paste0(i,"_tm")]), "%Y-%m-%d %H:%M", tz = "UTC")) + varval <- as.POSIXct(fast_strptime(paste(readr.data[,paste0(i,"_dt")],readr.data[,paste0(i,"_tm")]), "%Y-%m-%d %H:%M:%S", tz = "UTC")) if(!all(is.na(varval))){ readr.data[,varname] <- varval From bba77e9a4d2d71be89bca59cac5e6aa551727241 Mon Sep 17 00:00:00 2001 From: wdwatkins Date: Tue, 26 Jul 2016 10:16:23 -0500 Subject: [PATCH 2/2] didn't get all the changes last time --- R/importRDB1.r | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/R/importRDB1.r b/R/importRDB1.r index 288d2d71..a8bd41c1 100644 --- a/R/importRDB1.r +++ b/R/importRDB1.r @@ -43,17 +43,11 @@ #' @export #' @import utils #' @import stats +#' @import lubridate #' @importFrom dplyr left_join #' @importFrom readr read_lines #' @importFrom readr read_delim #' @importFrom readr problems -#' @importFrom lubridate fast_strptime -#' @importFrom lubridate parse_date_time -#' @importFrom lubridate seconds_to_period -#' @importFrom lubridate second -#' @importFrom lubridate minute -#' @importFrom lubridate hour -#' @import lubridate #' @examples #' siteNumber <- "02177000" #' startDate <- "2012-09-01" @@ -176,9 +170,8 @@ importRDB1 <- function(obs_url, asDateTime=TRUE, convertType = TRUE, tz=""){ if(all(c(paste0(i,"_dt"),paste0(i,"_tm")) %in% header.names)){ varname <- paste0(i,"_dateTime") - - varval <- as.POSIXct(fast_strptime(paste(readr.data[,paste0(i,"_dt")],readr.data[,paste0(i,"_tm")]), "%Y-%m-%d %H:%M:%S", tz = "UTC")) - + varval <- parse_date_time(paste(readr.data[,paste0(i,"_dt")],readr.data[,paste0(i,"_tm")]), c("%Y-%m-%d %H:%M:%S","%Y-%m-%d %H:%M"), tz = "UTC") + if(!all(is.na(varval))){ readr.data[,varname] <- varval tz.name <- paste0(i,"_time_datum_cd")