diff --git a/R/AR.R b/R/AR.R index f7b4cc999a79c47cc7ba3efcca732974dc3e86a8..91e5190523eee428db4e71eb3a29fb2c770860d2 100644 --- a/R/AR.R +++ b/R/AR.R @@ -50,7 +50,7 @@ #' fit <- rls_fit(c(lambda=0.99), model, D, returnanalysis=TRUE) #' #' # Plot the result, see "?plot_ts.rls_fit" -#' plot_ts(fit, xlim=c(act("2010-12-20"),max(D$t))) +#' plot_ts(fit, xlim=c(ct("2010-12-20"),max(D$t))) #' # Plot for a short period with peaks #' plot_ts(fit, xlim=c("2011-01-05","2011-01-07")) #' diff --git a/R/anlt.R b/R/aslt.R similarity index 59% rename from R/anlt.R rename to R/aslt.R index 6e142b4af298806e9665194ba5cbb9d9036003c6..9704860c0e7801a56cccc3643343fbadb24e8c52 100644 --- a/R/anlt.R +++ b/R/aslt.R @@ -2,8 +2,8 @@ #library(devtools) #document() #load_all(as.package("../../onlineforecast")) -#?anlt -#?anlt.default +#?aslt +#?aslt.default #' The argument is converted into POSIXlt with tz="GMT". #' @@ -18,56 +18,56 @@ #' #' @examples #' #' # Create a POSIXlt with tz="GMT" -#' anlt("2019-01-01") -#' class(anlt("2019-01-01")) -#' anlt("2019-01-01 01:00:05") +#' aslt("2019-01-01") +#' class(aslt("2019-01-01")) +#' aslt("2019-01-01 01:00:05") #' #' # Convert between time zones -#' x <- anlt("2019-01-01", tz="CET") -#' anlt(x,tz="GMT") +#' x <- aslt("2019-01-01", tz="CET") +#' aslt(x,tz="GMT") #' #' # To seconds and back again -#' anlt(as.numeric(x, units="sec")) +#' aslt(as.numeric(x, units="sec")) #' #' @export -anlt <- function(object, ...){ - UseMethod("anlt") +aslt <- function(object, ...){ + UseMethod("aslt") } -#' @rdname anlt +#' @rdname aslt #' @section Methods: -#' - anlt.character: Simply a wrapper for \code{as.POSIXlt} +#' - aslt.character: Simply a wrapper for \code{as.POSIXlt} #' @export -anlt.character <- function(object, tz = "GMT", ...){ +aslt.character <- function(object, tz = "GMT", ...){ as.POSIXlt(object, tz = tz, ...) } -#' @rdname anlt +#' @rdname aslt #' @section Methods: -#' - anlt.POSIXct: Converts to POSIXct. +#' - aslt.POSIXct: Converts to POSIXct. #' @export -anlt.POSIXct <- function(object, tz = NA, ...){ +aslt.POSIXct <- function(object, tz = NA, ...){ if(!is.na(tz)){ attr(object, "tzone") <- tz } as.POSIXlt(object, ...) } -#' @rdname anlt +#' @rdname aslt #' @section Methods: -#' - anlt.POSIXlt: Changes the time zone of the object if tz is given. +#' - aslt.POSIXlt: Changes the time zone of the object if tz is given. #' @export -anlt.POSIXlt <- function(object, tz = NA, ...){ +aslt.POSIXlt <- function(object, tz = NA, ...){ if(!is.na(tz)){ attr(object, "tzone") <- tz } return(object) } -#' @rdname anlt +#' @rdname aslt #' @section Methods: -#' - anlt.numeric: Converts from UNIX time in seconds to POSIXlt. +#' - aslt.numeric: Converts from UNIX time in seconds to POSIXlt. #' @export -anlt.numeric <- function(object, ...){ +aslt.numeric <- function(object, ...){ as.POSIXlt(ISOdate(1970, 1, 1, 0, ...) + object) } diff --git a/R/act.R b/R/ct.R similarity index 72% rename from R/act.R rename to R/ct.R index b93dc43daa408a2b6e92f6c2e042e79801c419a8..6feec91a74d2b8c11970b9af936b78b9b2ef4cce 100644 --- a/R/act.R +++ b/R/ct.R @@ -2,8 +2,8 @@ #library(devtools) #document() #load_all(as.package("../../onlineforecast")) -#?act -#?act.default +#?ct +#?ct.default #' The object is converted into POSIXct with tz="GMT". #' @@ -19,16 +19,16 @@ #' #' #' # Create a POSIXct with tz="GMT" -#' act("2019-01-01") -#' class(act("2019-01-01")) -#' act("2019-01-01 01:00:05") +#' ct("2019-01-01") +#' class(ct("2019-01-01")) +#' ct("2019-01-01 01:00:05") #' #' #' # Convert to POSIXct -#' class(act(as.POSIXlt("2019-01-01"))) +#' class(ct(as.POSIXlt("2019-01-01"))) #' #' # To seconds and back again -#' act(as.numeric(1000, units="sec")) +#' ct(as.numeric(1000, units="sec")) #' #' #' # -------- @@ -45,20 +45,20 @@ #' "2019-03-31 01:30", #' "2019-03-31 03:00", #' "2019-03-31 03:30") -#' x <- act(txt, tz="CET") +#' x <- ct(txt, tz="CET") #' x -#' act(x, tz="GMT") +#' ct(x, tz="GMT") #' #' # BE AWARE of this conversion of the 02:00: to 02:59:59 (exact time of shift) will lead to a #' # wrong conversion #' txt <- c("2019-03-31 01:30", #' "2019-03-31 02:00", #' "2019-03-31 03:30") -#' x <- act(txt, tz="CET") +#' x <- ct(txt, tz="CET") #' x -#' act(x, tz="GMT") +#' ct(x, tz="GMT") #' # Which a diff on the time can detect, since all steps are not equal -#' plot(diff(act(x, tz="GMT"))) +#' plot(diff(ct(x, tz="GMT"))) #' #' # -------- #' # Shift to winter time is more problematic @@ -68,9 +68,9 @@ #' "2019-10-27 02:30", #' "2019-10-27 03:00", #' "2019-10-27 03:30") -#' x <- act(txt, tz="CET") +#' x <- ct(txt, tz="CET") #' x -#' act(x, tz="GMT") +#' ct(x, tz="GMT") #' #' # however, timestamps can be given like this #' txt <- c("2019-10-27 01:30", @@ -80,35 +80,35 @@ #' "2019-10-27 02:30", #' "2019-10-27 03:00", #' "2019-10-27 03:30") -#' x <- act(txt, tz="CET") +#' x <- ct(txt, tz="CET") #' x -#' act(x, tz="GMT") +#' ct(x, tz="GMT") #' # Again can be detected, since all steps are not equal -#' plot(diff(act(x, tz="GMT"))) +#' plot(diff(ct(x, tz="GMT"))) #' # This can be fixed by (note that it can go wrong, e.g. with gaps around convertion etc.) -#' act(x, tz="GMT", duplicatedadd=3600) +#' ct(x, tz="GMT", duplicatedadd=3600) #' #' @export -act <- function(object, ...){ - UseMethod("act") +ct <- function(object, ...){ + UseMethod("ct") } -#' @rdname act +#' @rdname ct #' @section Methods: -#' - act.character: Simply a wrapper for \code{as.POSIXct} with default \code{tz} +#' - ct.character: Simply a wrapper for \code{as.POSIXct} with default \code{tz} #' @export -act.character <- function(object, tz = "GMT", ...){ +ct.character <- function(object, tz = "GMT", ...){ as.POSIXct(object, tz=tz, ...) } -#' @rdname act +#' @rdname ct #' @param duplicatedadd Seconds to be added to duplicated time stamps, to mitigate the problem of duplicated timestamps at the shift to winter time. So the second time a time stamp occurs (identified with \code{duplicated}) then the seconds will be added. #' @section Methods: -#' - act.POSIXct: Changes the time zone of the object if \code{tz} is given. +#' - ct.POSIXct: Changes the time zone of the object if \code{tz} is given. #' @export -act.POSIXct <- function(object, tz = NA, duplicatedadd = NA, ...){ +ct.POSIXct <- function(object, tz = NA, duplicatedadd = NA, ...){ if(!is.na(tz)){ attr(object, "tzone") <- tz } @@ -120,18 +120,18 @@ act.POSIXct <- function(object, tz = NA, duplicatedadd = NA, ...){ return(object) } -#' @rdname act +#' @rdname ct #' @section Methods: -#' - act.POSIXlt: Converts to POSIXct. +#' - ct.POSIXlt: Converts to POSIXct. #' @export -act.POSIXlt <- function(object, tz = NA, duplicatedadd = NA, ...){ - as.POSIXct(act.POSIXct(object, tz, duplicatedadd), ...) +ct.POSIXlt <- function(object, tz = NA, duplicatedadd = NA, ...){ + as.POSIXct(ct.POSIXct(object, tz, duplicatedadd), ...) } -#' @rdname act +#' @rdname ct #' @section Methods: -#' - act.numeric: Converts from UNIX time in seconds to POSIXct with \code{tz} as GMT. +#' - ct.numeric: Converts from UNIX time in seconds to POSIXct with \code{tz} as GMT. #' @export -act.numeric <- function(object, ...){ +ct.numeric <- function(object, ...){ ISOdate(1970, 1, 1, 0, ...) + object } diff --git a/R/data.list.R b/R/data.list.R index 3d652196be88845839cc896d12f9dbd0db77ecaf..794e9e14e500f80c1010d612eea98f86f182d386 100644 --- a/R/data.list.R +++ b/R/data.list.R @@ -23,7 +23,7 @@ #' @examples #' # Put together a data.list #' # The time vector -#' time <- seq(act("2019-01-01"),act("2019-01-02"),by=3600) +#' time <- seq(ct("2019-01-01"),ct("2019-01-02"),by=3600) #' # Observations time series (as vector) #' x.obs <- rnorm(length(time)) #' # Forecast input as data.frame diff --git a/R/fs.R b/R/fs.R index e5f71edea78cf290351f79e38ffcbac741ca3dbc..87df53bbffaaee0a1983c0d18f5f5d75ab5151c2 100644 --- a/R/fs.R +++ b/R/fs.R @@ -9,7 +9,7 @@ #' @return Returns a list of dataframes (two for each i in \code{1:nharmonics}) with same number of columns as X. #' @examples #' # Make a data.frame with time of day in hours for different horizons -#' tday <- make_tday(seq(act("2019-01-01"), act("2019-01-04"), by=3600), kseq=1:5) +#' tday <- make_tday(seq(ct("2019-01-01"), ct("2019-01-04"), by=3600), kseq=1:5) #' # See whats in it #' str(tday) #' head(tday) diff --git a/R/in_range.R b/R/in_range.R index c860fa9ade3f1bee7909f00659a65b438b353e5d..368be5cd57ee826de75e0bf903ebd625e8c8987a 100644 --- a/R/in_range.R +++ b/R/in_range.R @@ -48,10 +48,10 @@ in_range <- function(tstart, time, tend=NA) { if (class(tstart)[1] == "character") - tstart <- act(tstart) + tstart <- ct(tstart) if (is.na(tend)) tend <- time[length(time)] if (class(tend)[1] == "character") - tend <- act(tend) - act(tstart) < time & time <= act(tend) + tend <- ct(tend) + ct(tstart) < time & time <= ct(tend) } diff --git a/R/make_tday.R b/R/make_tday.R index b80c86b4f95fa456eb49f0f7c21ff19c853ae77e..ab21fd5fe3f39f1ca67eea060911100bff5b50d5 100644 --- a/R/make_tday.R +++ b/R/make_tday.R @@ -18,7 +18,7 @@ #' @keywords hourofday lags data.frame #' @examples #' # Create a time sequence -#' tseq <- seq(act("2019-01-01"), act("2019-02-01 12:00"), by=1800) +#' tseq <- seq(ct("2019-01-01"), ct("2019-02-01 12:00"), by=1800) #' #' # Make the time of day sequence #' make_tday(tseq, 1:10) diff --git a/R/resample.R b/R/resample.R index a12e2869fbb4dc6e62bdce8ba461a96cedc07b7c..0a60873e1d88f5737d0535c6e9d746f66cc386e3 100644 --- a/R/resample.R +++ b/R/resample.R @@ -32,7 +32,7 @@ #' @examples #' #' # Generate some test data with 10 minutes sampling frequency for one day -#' X <- data.frame(t=seq(act("2019-01-01 00:10"),act("2019-01-02"), by=10*60)) +#' X <- data.frame(t=seq(ct("2019-01-01 00:10"),ct("2019-01-02"), by=10*60)) #' #' # A single sine over the day #' X$val <- sin(as.numeric(X$t)/3600*2*pi/(24)) @@ -73,8 +73,8 @@ resample.data.frame <- function(object, ts, tstart=NA, tend=NA, timename="t", fu # ---------------------------------------------------------------- # Convert to POSIXct - tstart <- act(tstart) - tend <- act(tend) + tstart <- ct(tstart) + tend <- ct(tend) # ---------------------------------------------------------------- # Cut out the time period diff --git a/R/setpar.R b/R/setpar.R index 8220c9a3588415a259c951f4444e7988eadcbedf..a3c1f45ce40ad03b937b83a35f80acf052ea694d 100644 --- a/R/setpar.R +++ b/R/setpar.R @@ -2,7 +2,7 @@ #library(devtools) #document() #load_all(as.package("../../onlineforecast")) -#?anlt +#?aslt #' Setting \code{\link{par}()} plotting parameters to a set of default values #' @@ -18,7 +18,7 @@ #' @examples #' #' # Make some data -#' D <- data.frame(t=seq(act("2020-01-01"),act("2020-01-10"),len=100), x=rnorm(100), y=runif(100)) +#' D <- data.frame(t=seq(ct("2020-01-01"),ct("2020-01-10"),len=100), x=rnorm(100), y=runif(100)) #' #' # Generate two stacked plots with same x-axis #' setpar("ts", mfrow=c(2,1)) diff --git a/data/all/make.R b/data/all/make.R index 20043b62d915bca3489b37cb080bfb88091039c7..18be8d50cdc65030aef980235118d348c0b4aedb 100644 --- a/data/all/make.R +++ b/data/all/make.R @@ -16,7 +16,7 @@ load_all(pack) # Importing data # First unzip to get the .csv system('unzip # ../data/DataSoenderborg.zip') data_or <- fread("data_soenderborg.csv", sep = ",", header = TRUE) -data_or[, `:=`(t, act(data_or$t))] +data_or[, `:=`(t, ct(data_or$t))] setDF(data_or) names(data_or)[names(data_or) == "Ig.obs"] <- "I.obs" @@ -56,7 +56,7 @@ data[["sunElevation"]] <- data_or[, "sunElevation.obs"] # # The time of day # ncol <- ncol(data$Ta) -# tmp <- anlt(data$t)$hour +# tmp <- aslt(data$t)$hour # tmp <- matrix(tmp, nrow = length(tmp), ncol = ncol) # tmp <- data.frame(t(t(tmp) + (0:(ncol - 1)))) # names(tmp) <- pst("k", 0:(ncol - 1)) diff --git a/vignettes/forecast-evaluation.Rmd b/vignettes/forecast-evaluation.Rmd index 953e1d59b3bb87562e63843bedd49eb991facee0..33bf041f01fc1c8ebd6e1c2f018fb1c7e954d3db 100644 --- a/vignettes/forecast-evaluation.Rmd +++ b/vignettes/forecast-evaluation.Rmd @@ -447,7 +447,7 @@ A pairs plot with residuals and inputs to see if patterns are left: ```{r plotpairs, fig.height=figwidth} kseq <- c(1,36) D$Residuals <- residuals(fit2)[ ,pst("h",kseq)] -D$hour <- anlt(D$t)$hour +D$hour <- aslt(D$t)$hour pairs(D, subset=D$scoreperiod, pattern="Residuals|Ta|I|hour|^t$", kseq=kseq) ``` So inspecting the two upper rows, there are no clear patterns to be seen for the diff --git a/vignettes/setup-data.Rmd b/vignettes/setup-data.Rmd index b409c211ef658f957ca4c00a2059bd997dd3f142..727d1371dab879d2c7311fdd9ea759343381e0f0 100644 --- a/vignettes/setup-data.Rmd +++ b/vignettes/setup-data.Rmd @@ -180,9 +180,9 @@ A helper function is provided with the `asp` function which can be called using ```{r} ## Convert from a time stamp (tz="GMT" per default) -act("2019-01-01 11:00") +ct("2019-01-01 11:00") ## Convert from unix time -act(3840928387) +ct(3840928387) ``` Note that for all functions where a time value as a character is given, the time zone is always "GMT" (or "UTC", but this can result in warnings, but they can be