From f54d3b50aea73ef93f88860fdb713ee6af010d27 Mon Sep 17 00:00:00 2001 From: Ben Letham Date: Thu, 1 Feb 2018 17:21:55 -0800 Subject: [PATCH] R set_date robust to NAs --- R/R/prophet.R | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/R/R/prophet.R b/R/R/prophet.R index 2eb4e46..8a23f53 100644 --- a/R/R/prophet.R +++ b/R/R/prophet.R @@ -274,7 +274,7 @@ set_date <- function(ds = NULL, tz = "GMT") { ds <- as.character(ds) } - if (min(nchar(ds)) < 12) { + if (min(nchar(ds), na.rm=TRUE) < 12) { ds <- as.POSIXct(ds, format = "%Y-%m-%d", tz = tz) } else { ds <- as.POSIXct(ds, format = "%Y-%m-%d %H:%M:%S", tz = tz) @@ -321,8 +321,9 @@ setup_dataframe <- function(m, df, initialize_scales = FALSE) { } df$ds <- set_date(df$ds) if (anyNA(df$ds)) { - stop(paste('Unable to parse date format in column ds. Convert to date ', - 'format. Either %Y-%m-%d or %Y-%m-%d %H:%M:%S')) + stop(paste('Unable to parse date format in column ds. Convert to date', + 'format (%Y-%m-%d or %Y-%m-%d %H:%M:%S) and check that there', + 'are no NAs.')) } for (name in names(m$extra_regressors)) { if (!(name %in% colnames(df))) {