diff --git a/R/SeriesAggreg.R b/R/SeriesAggreg.R index 3bb2231058e663b3dfcade6ccf79211a23ae08b1..1192516982a46f168ff1e7760bd5477b48cb43ef 100644 --- a/R/SeriesAggreg.R +++ b/R/SeriesAggreg.R @@ -7,10 +7,16 @@ SeriesAggreg <- function(TabSeries, TimeFormat, NewTimeFormat, ConvertFun, YearF if(is.null(TabSeries) ){ stop("TabSeries must be a dataframe containing the dates and data to be converted \n"); return(NULL); } if(!is.data.frame(TabSeries)){ stop("TabSeries must be a dataframe containing the dates and data to be converted \n"); return(NULL); } if(ncol(TabSeries)<2){ stop("TabSeries must contain at least two columns (including the coulmn of dates \n"); return(NULL); } - if("POSIXlt" %in% class(TabSeries[,1]) == FALSE & "POSIXct" %in% class(TabSeries[,1]) == FALSE){ stop("TabSeries first column must be a vector of class POSIXlt or POSIXct \n"); return(NULL); } + ##check_TimeFormat + if(!any(class(TabSeries[,1]) %in% "POSIXt")) { + stop("TabSeries first column must be a vector of class POSIXlt or POSIXct \n") + return(NULL) + } + if(any(class(TabSeries[,1]) %in% "POSIXlt")) { + TabSeries[,1] <- as.POSIXct(TabSeries[,1]) + } for(iCol in 2:ncol(TabSeries)){ if(!is.numeric(TabSeries[,iCol])){ stop("TabSeries columns (other than the first one) be of numeric class \n"); return(NULL); } } - ##check_TimeFormat if(is.null( TimeFormat)){ stop("TimeFormat must be 'hourly', 'daily', 'monthly' or 'yearly' \n"); return(NULL); } if(!is.vector( TimeFormat)){ stop("TimeFormat must be 'hourly', 'daily', 'monthly' or 'yearly' \n"); return(NULL); } if(!is.character(TimeFormat)){ stop("TimeFormat must be 'hourly', 'daily', 'monthly' or 'yearly' \n"); return(NULL); } diff --git a/man/SeriesAggreg.Rd b/man/SeriesAggreg.Rd index 4e374374153eedffb487096f49bb265307db8164..40e46d543702483e5dc0e0387a4a3d7bd6402a07 100644 --- a/man/SeriesAggreg.Rd +++ b/man/SeriesAggreg.Rd @@ -7,7 +7,7 @@ SeriesAggreg(TabSeries, TimeFormat, NewTimeFormat, ConvertFun, YearFirstMonth = 1, TimeLag = 0, verbose = TRUE) } \arguments{ -\item{TabSeries}{[POSIXlt+numeric] dataframe containing the vector of dates and the time series values} +\item{TabSeries}{[POSIXt+numeric] dataframe containing the vector of dates (POSIXt) and the time series values numeric)} \item{TimeFormat}{[character] desired format (i.e. "hourly", "daily", "monthly" or "yearly")} @@ -22,7 +22,7 @@ SeriesAggreg(TabSeries, TimeFormat, NewTimeFormat, ConvertFun, \item{verbose}{(optional) [boolean] boolean indicating if the function is run in verbose mode or not, default = FALSE} } \value{ -[POSIXlt+numeric] dataframe containing a vector of aggregated dates and time series values +[POSIXct+numeric] dataframe containing a vector of aggregated dates (POSIXct) and time series values numeric) } \description{ Conversion of time series to another time step (aggregation only). \cr