From 37f59caa5e664a96d635a0e80ce7123a9ebda7b0 Mon Sep 17 00:00:00 2001 From: thoenis Date: Wed, 12 Dec 2018 15:05:25 +0100 Subject: [PATCH] Make long_to_ts jus treturn a list() if all values == NA Previously it would fail --- R/import_helpers.R | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/R/import_helpers.R b/R/import_helpers.R index cc4d443..00e935f 100644 --- a/R/import_helpers.R +++ b/R/import_helpers.R @@ -35,6 +35,10 @@ long_to_ts <- function(data, keep_last_freq_only = FALSE, force_xts = FALSE) { data_dt <- data_dt[!(series %in% empty_series[is_empty == TRUE, series])] + if(nrow(data_dt) == 0) { + return(list()) + } + data_dt[, `:=`(date_zoo = as.numeric(as.yearmon(date)), frq = 12), by = series] data_dt[is.na(date_zoo), `:=`(date_zoo = as.numeric(as.yearqtr(date)), frq = 4)]