Skip to content

Commit

Permalink
Merge pull request #257 from wdwatkins/master
Browse files Browse the repository at this point in the history
Fixed issue with new readr
  • Loading branch information
ldecicco-USGS authored Jul 26, 2016
2 parents 29706b1 + bba77e9 commit edeff72
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions R/importRDB1.r
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +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
#' @examples
#' siteNumber <- "02177000"
#' startDate <- "2012-09-01"
Expand Down Expand Up @@ -117,6 +116,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"))
}
Expand Down Expand Up @@ -166,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", 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")
Expand Down

0 comments on commit edeff72

Please sign in to comment.