diff --git a/R/AR.R b/R/AR.R index 8b8a156cd2d0db3083e3e245e85494201881d796..f7b4cc999a79c47cc7ba3efcca732974dc3e86a8 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(asct("2010-12-20"),max(D$t))) +#' plot_ts(fit, xlim=c(act("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/asct.R b/R/act.R similarity index 71% rename from R/asct.R rename to R/act.R index 344556c3fabca6250ab10fa589d9637fc378b1e4..b93dc43daa408a2b6e92f6c2e042e79801c419a8 100644 --- a/R/asct.R +++ b/R/act.R @@ -2,8 +2,8 @@ #library(devtools) #document() #load_all(as.package("../../onlineforecast")) -#?asct -#?asct.default +#?act +#?act.default #' The object is converted into POSIXct with tz="GMT". #' @@ -19,16 +19,16 @@ #' #' #' # Create a POSIXct with tz="GMT" -#' asct("2019-01-01") -#' class(asct("2019-01-01")) -#' asct("2019-01-01 01:00:05") +#' act("2019-01-01") +#' class(act("2019-01-01")) +#' act("2019-01-01 01:00:05") #' #' #' # Convert to POSIXct -#' class(asct(as.POSIXlt("2019-01-01"))) +#' class(act(as.POSIXlt("2019-01-01"))) #' #' # To seconds and back again -#' asct(as.numeric(1000, units="sec")) +#' act(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 <- asct(txt, tz="CET") +#' x <- act(txt, tz="CET") #' x -#' asct(x, tz="GMT") +#' act(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 <- asct(txt, tz="CET") +#' x <- act(txt, tz="CET") #' x -#' asct(x, tz="GMT") +#' act(x, tz="GMT") #' # Which a diff on the time can detect, since all steps are not equal -#' plot(diff(asct(x, tz="GMT"))) +#' plot(diff(act(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 <- asct(txt, tz="CET") +#' x <- act(txt, tz="CET") #' x -#' asct(x, tz="GMT") +#' act(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 <- asct(txt, tz="CET") +#' x <- act(txt, tz="CET") #' x -#' asct(x, tz="GMT") +#' act(x, tz="GMT") #' # Again can be detected, since all steps are not equal -#' plot(diff(asct(x, tz="GMT"))) +#' plot(diff(act(x, tz="GMT"))) #' # This can be fixed by (note that it can go wrong, e.g. with gaps around convertion etc.) -#' asct(x, tz="GMT", duplicatedadd=3600) +#' act(x, tz="GMT", duplicatedadd=3600) #' #' @export -asct <- function(object, ...){ - UseMethod("asct") +act <- function(object, ...){ + UseMethod("act") } -#' @rdname asct +#' @rdname act #' @section Methods: -#' - asct.character: Simply a wrapper for \code{as.POSIXct} with default \code{tz} +#' - act.character: Simply a wrapper for \code{as.POSIXct} with default \code{tz} #' @export -asct.character <- function(object, tz = "GMT", ...){ +act.character <- function(object, tz = "GMT", ...){ as.POSIXct(object, tz=tz, ...) } -#' @rdname asct +#' @rdname act #' @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: -#' - asct.POSIXct: Changes the time zone of the object if \code{tz} is given. +#' - act.POSIXct: Changes the time zone of the object if \code{tz} is given. #' @export -asct.POSIXct <- function(object, tz = NA, duplicatedadd = NA, ...){ +act.POSIXct <- function(object, tz = NA, duplicatedadd = NA, ...){ if(!is.na(tz)){ attr(object, "tzone") <- tz } @@ -120,18 +120,18 @@ asct.POSIXct <- function(object, tz = NA, duplicatedadd = NA, ...){ return(object) } -#' @rdname asct +#' @rdname act #' @section Methods: -#' - asct.POSIXlt: Converts to POSIXct. +#' - act.POSIXlt: Converts to POSIXct. #' @export -asct.POSIXlt <- function(object, tz = NA, duplicatedadd = NA, ...){ - as.POSIXct(asct.POSIXct(object, tz, duplicatedadd), ...) +act.POSIXlt <- function(object, tz = NA, duplicatedadd = NA, ...){ + as.POSIXct(act.POSIXct(object, tz, duplicatedadd), ...) } -#' @rdname asct +#' @rdname act #' @section Methods: -#' - asct.numeric: Converts from UNIX time in seconds to POSIXct with \code{tz} as GMT. +#' - act.numeric: Converts from UNIX time in seconds to POSIXct with \code{tz} as GMT. #' @export -asct.numeric <- function(object, ...){ +act.numeric <- function(object, ...){ ISOdate(1970, 1, 1, 0, ...) + object } diff --git a/R/aslt.R b/R/anlt.R similarity index 59% rename from R/aslt.R rename to R/anlt.R index 9704860c0e7801a56cccc3643343fbadb24e8c52..6e142b4af298806e9665194ba5cbb9d9036003c6 100644 --- a/R/aslt.R +++ b/R/anlt.R @@ -2,8 +2,8 @@ #library(devtools) #document() #load_all(as.package("../../onlineforecast")) -#?aslt -#?aslt.default +#?anlt +#?anlt.default #' The argument is converted into POSIXlt with tz="GMT". #' @@ -18,56 +18,56 @@ #' #' @examples #' #' # Create a POSIXlt with tz="GMT" -#' aslt("2019-01-01") -#' class(aslt("2019-01-01")) -#' aslt("2019-01-01 01:00:05") +#' anlt("2019-01-01") +#' class(anlt("2019-01-01")) +#' anlt("2019-01-01 01:00:05") #' #' # Convert between time zones -#' x <- aslt("2019-01-01", tz="CET") -#' aslt(x,tz="GMT") +#' x <- anlt("2019-01-01", tz="CET") +#' anlt(x,tz="GMT") #' #' # To seconds and back again -#' aslt(as.numeric(x, units="sec")) +#' anlt(as.numeric(x, units="sec")) #' #' @export -aslt <- function(object, ...){ - UseMethod("aslt") +anlt <- function(object, ...){ + UseMethod("anlt") } -#' @rdname aslt +#' @rdname anlt #' @section Methods: -#' - aslt.character: Simply a wrapper for \code{as.POSIXlt} +#' - anlt.character: Simply a wrapper for \code{as.POSIXlt} #' @export -aslt.character <- function(object, tz = "GMT", ...){ +anlt.character <- function(object, tz = "GMT", ...){ as.POSIXlt(object, tz = tz, ...) } -#' @rdname aslt +#' @rdname anlt #' @section Methods: -#' - aslt.POSIXct: Converts to POSIXct. +#' - anlt.POSIXct: Converts to POSIXct. #' @export -aslt.POSIXct <- function(object, tz = NA, ...){ +anlt.POSIXct <- function(object, tz = NA, ...){ if(!is.na(tz)){ attr(object, "tzone") <- tz } as.POSIXlt(object, ...) } -#' @rdname aslt +#' @rdname anlt #' @section Methods: -#' - aslt.POSIXlt: Changes the time zone of the object if tz is given. +#' - anlt.POSIXlt: Changes the time zone of the object if tz is given. #' @export -aslt.POSIXlt <- function(object, tz = NA, ...){ +anlt.POSIXlt <- function(object, tz = NA, ...){ if(!is.na(tz)){ attr(object, "tzone") <- tz } return(object) } -#' @rdname aslt +#' @rdname anlt #' @section Methods: -#' - aslt.numeric: Converts from UNIX time in seconds to POSIXlt. +#' - anlt.numeric: Converts from UNIX time in seconds to POSIXlt. #' @export -aslt.numeric <- function(object, ...){ +anlt.numeric <- function(object, ...){ as.POSIXlt(ISOdate(1970, 1, 1, 0, ...) + object) } diff --git a/R/data.list.R b/R/data.list.R index 97adc83ef2f86d1d18094c180ea14becd8350579..3d652196be88845839cc896d12f9dbd0db77ecaf 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(asct("2019-01-01"),asct("2019-01-02"),by=3600) +#' time <- seq(act("2019-01-01"),act("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 26fd928af7aa659660ed1d0cb2c5c425f7039bcf..e5f71edea78cf290351f79e38ffcbac741ca3dbc 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(asct("2019-01-01"), asct("2019-01-04"), by=3600), kseq=1:5) +#' tday <- make_tday(seq(act("2019-01-01"), act("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 a5739ea723851e73c9c0627c8944b36ab1d7e107..c860fa9ade3f1bee7909f00659a65b438b353e5d 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 <- asct(tstart) + tstart <- act(tstart) if (is.na(tend)) tend <- time[length(time)] if (class(tend)[1] == "character") - tend <- asct(tend) - asct(tstart) < time & time <= asct(tend) + tend <- act(tend) + act(tstart) < time & time <= act(tend) } diff --git a/R/make_tday.R b/R/make_tday.R index 0c3584d093fb11c8485fc138232cfccdc00cd0c5..b80c86b4f95fa456eb49f0f7c21ff19c853ae77e 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(asct("2019-01-01"), asct("2019-02-01 12:00"), by=1800) +#' tseq <- seq(act("2019-01-01"), act("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 6c1f6b20c6171b448859354536dfc37c4a36f11b..a12e2869fbb4dc6e62bdce8ba461a96cedc07b7c 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(asct("2019-01-01 00:10"),asct("2019-01-02"), by=10*60)) +#' X <- data.frame(t=seq(act("2019-01-01 00:10"),act("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 <- asct(tstart) - tend <- asct(tend) + tstart <- act(tstart) + tend <- act(tend) # ---------------------------------------------------------------- # Cut out the time period diff --git a/R/setpar.R b/R/setpar.R index b993527c50a5f6a1acb884c7351bee9155643f46..8220c9a3588415a259c951f4444e7988eadcbedf 100644 --- a/R/setpar.R +++ b/R/setpar.R @@ -2,7 +2,7 @@ #library(devtools) #document() #load_all(as.package("../../onlineforecast")) -#?aslt +#?anlt #' 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(asct("2020-01-01"),asct("2020-01-10"),len=100), x=rnorm(100), y=runif(100)) +#' D <- data.frame(t=seq(act("2020-01-01"),act("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 e8ff2ad1da24f097b40196eee4ea4b81e04fae82..20043b62d915bca3489b37cb080bfb88091039c7 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, asct(data_or$t))] +data_or[, `:=`(t, act(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 <- aslt(data$t)$hour +# tmp <- anlt(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/make.R b/make.R index fcc47a1d3c41ee8bd265afe807f6c7f24a555813..0f98702e5e5b204283cd735dc222dc4625925c8c 100644 --- a/make.R +++ b/make.R @@ -43,6 +43,7 @@ library(roxygen2) #use_test("newtest") # # Run all tests +document() test() # # Run the examples diff --git a/vignettes/forecast-evaluation.Rmd b/vignettes/forecast-evaluation.Rmd index 33bf041f01fc1c8ebd6e1c2f018fb1c7e954d3db..953e1d59b3bb87562e63843bedd49eb991facee0 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 <- aslt(D$t)$hour +D$hour <- anlt(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 c8950db061c82639861c827107bec8466bee9a1e..b409c211ef658f957ca4c00a2059bd997dd3f142 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) -asct("2019-01-01 11:00") +act("2019-01-01 11:00") ## Convert from unix time -asct(3840928387) +act(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