Binary files /tmp/xZFphps19Q/r-zoo-1.7-11/build/vignette.rds and /tmp/p6_J8sJim1/r-zoo-1.7-12/build/vignette.rds differ diff -Nru r-zoo-1.7-11/debian/changelog r-zoo-1.7-12/debian/changelog --- r-zoo-1.7-11/debian/changelog 2015-07-30 07:41:49.000000000 +0000 +++ r-zoo-1.7-12/debian/changelog 2015-07-30 07:41:50.000000000 +0000 @@ -1,3 +1,12 @@ +r-zoo (1.7-12-1) unstable; urgency=low + + * New upstream release + + * debian/control: Set Build-Depends: to current R version + * debian/control: Set Standards-Version: to current version + + -- Dirk Eddelbuettel Mon, 16 Mar 2015 15:43:10 -0500 + r-zoo (1.7-11-1) unstable; urgency=low * New upstream release diff -Nru r-zoo-1.7-11/debian/control r-zoo-1.7-12/debian/control --- r-zoo-1.7-11/debian/control 2015-07-30 07:41:49.000000000 +0000 +++ r-zoo-1.7-12/debian/control 2015-07-30 07:41:50.000000000 +0000 @@ -2,8 +2,8 @@ Section: gnu-r Priority: optional Maintainer: Dirk Eddelbuettel -Build-Depends: debhelper (>= 7.0.0), cdbs, r-base-dev (>= 3.0.2), r-cran-lattice (>= 0.20-27) -Standards-Version: 3.9.5 +Build-Depends: debhelper (>= 7.0.0), cdbs, r-base-dev (>= 3.1.3), r-cran-lattice (>= 0.20-27) +Standards-Version: 3.9.6 Package: r-cran-zoo Architecture: any diff -Nru r-zoo-1.7-11/DESCRIPTION r-zoo-1.7-12/DESCRIPTION --- r-zoo-1.7-11/DESCRIPTION 2014-02-27 10:46:02.000000000 +0000 +++ r-zoo-1.7-12/DESCRIPTION 2015-03-16 18:13:58.000000000 +0000 @@ -1,8 +1,8 @@ Package: zoo -Version: 1.7-11 -Date: 2014-02-27 +Version: 1.7-12 +Date: 2015-03-16 Title: S3 Infrastructure for Regular and Irregular Time Series (Z's - ordered observations) + Ordered Observations) Authors@R: c(person(given = "Achim", family = "Zeileis", role = c("aut", "cre"), email = "Achim.Zeileis@R-project.org"), person(given = "Gabor", family = "Grothendieck", role = "aut", email = "ggrothendieck@gmail.com"), person(given = c("Jeffrey", "A."), family = "Ryan", role = "aut", email = "jeff.a.ryan@gmail.com"), @@ -19,7 +19,7 @@ Imports: utils, graphics, grDevices, lattice (>= 0.20-27) License: GPL-2 | GPL-3 URL: http://zoo.R-Forge.R-project.org/ -Packaged: 2014-02-27 08:32:43 UTC; zeileis +Packaged: 2015-03-16 13:27:04 UTC; zeileis Author: Achim Zeileis [aut, cre], Gabor Grothendieck [aut], Jeffrey A. Ryan [aut], @@ -27,4 +27,4 @@ Maintainer: Achim Zeileis NeedsCompilation: yes Repository: CRAN -Date/Publication: 2014-02-27 11:46:02 +Date/Publication: 2015-03-16 19:13:58 Binary files /tmp/xZFphps19Q/r-zoo-1.7-11/inst/doc/zoo-design.pdf and /tmp/p6_J8sJim1/r-zoo-1.7-12/inst/doc/zoo-design.pdf differ Binary files /tmp/xZFphps19Q/r-zoo-1.7-11/inst/doc/zoo-faq.pdf and /tmp/p6_J8sJim1/r-zoo-1.7-12/inst/doc/zoo-faq.pdf differ Binary files /tmp/xZFphps19Q/r-zoo-1.7-11/inst/doc/zoo.pdf and /tmp/p6_J8sJim1/r-zoo-1.7-12/inst/doc/zoo.pdf differ Binary files /tmp/xZFphps19Q/r-zoo-1.7-11/inst/doc/zoo-quickref.pdf and /tmp/p6_J8sJim1/r-zoo-1.7-12/inst/doc/zoo-quickref.pdf differ diff -Nru r-zoo-1.7-11/inst/doc/zoo-quickref.R r-zoo-1.7-12/inst/doc/zoo-quickref.R --- r-zoo-1.7-11/inst/doc/zoo-quickref.R 2014-02-27 08:32:35.000000000 +0000 +++ r-zoo-1.7-12/inst/doc/zoo-quickref.R 2015-03-16 13:26:56.000000000 +0000 @@ -14,6 +14,7 @@ ################################################### ### code chunk number 2: read.zoo ################################################### +Sys.setlocale("LC_TIME", "C") inrusd <- read.zoo("demo1.txt", sep = "|", format="%d %b %Y") diff -Nru r-zoo-1.7-11/inst/doc/zoo-quickref.Rnw r-zoo-1.7-12/inst/doc/zoo-quickref.Rnw --- r-zoo-1.7-11/inst/doc/zoo-quickref.Rnw 2014-02-27 08:32:35.000000000 +0000 +++ r-zoo-1.7-12/inst/doc/zoo-quickref.Rnw 2015-03-16 13:26:56.000000000 +0000 @@ -70,10 +70,14 @@ \end{verbatim} can be read in via <>= +Sys.setlocale("LC_TIME", "C") inrusd <- read.zoo("demo1.txt", sep = "|", format="%d %b %Y") @ The \code{format} argument causes the first column to be transformed -to an index of class \code{"Date"}. +to an index of class \code{"Date"}. The \code{Sys.setlocale} is set to +\code{"C"} here to assure that the English month abbreviations are read +correctly. (It is unnecessary if the system is already set to a locale +that understands English month abbreviations.) The data in \code{demo2.txt} look like \begin{verbatim} diff -Nru r-zoo-1.7-11/inst/doc/zoo.R r-zoo-1.7-12/inst/doc/zoo.R --- r-zoo-1.7-11/inst/doc/zoo.R 1970-01-01 00:00:00.000000000 +0000 +++ r-zoo-1.7-12/inst/doc/zoo.R 2015-03-16 13:26:56.000000000 +0000 @@ -0,0 +1,389 @@ +### R code from vignette source 'zoo.Rnw' + +################################################### +### code chunk number 1: preliminaries +################################################### +library("zoo") +library("tseries") +library("strucchange") +library("timeDate") +online <- FALSE ## if set to FALSE the local copy of MSFT.rda + ## is used instead of get.hist.quote() +options(prompt = "R> ") +Sys.setenv(TZ = "GMT") + + +################################################### +### code chunk number 2: zoo-prelim +################################################### +library("zoo") +set.seed(1071) + + +################################################### +### code chunk number 3: zoo-vectors1 +################################################### +z1.index <- ISOdatetime(2004, rep(1:2,5), sample(28,10), 0, 0, 0) +z1.data <- rnorm(10) +z1 <- zoo(z1.data, z1.index) + + +################################################### +### code chunk number 4: zoo-vectors2 +################################################### +z2.index <- as.POSIXct(paste(2004, rep(1:2, 5), sample(1:28, 10), + sep = "-")) +z2.data <- sin(2*1:10/pi) +z2 <- zoo(z2.data, z2.index) + + +################################################### +### code chunk number 5: zoo-matrix +################################################### +Z.index <- as.Date(sample(12450:12500, 10)) +Z.data <- matrix(rnorm(30), ncol = 3) +colnames(Z.data) <- c("Aa", "Bb", "Cc") +Z <- zoo(Z.data, Z.index) + + +################################################### +### code chunk number 6: print1 +################################################### +z1 +z1[3:7] + + +################################################### +### code chunk number 7: print2 +################################################### +Z +Z[1:3, 2:3] + + +################################################### +### code chunk number 8: subset +################################################### +z1[ISOdatetime(2004, 1, c(14, 25), 0, 0, 0)] + + +################################################### +### code chunk number 9: summary +################################################### +summary(z1) +summary(Z) + + +################################################### +### code chunk number 10: zooreg1 +################################################### +zr1 <- zooreg(sin(1:9), start = 2000, frequency = 4) +zr2 <- zoo(sin(1:9), seq(2000, 2002, by = 1/4), 4) +zr1 +zr2 + + +################################################### +### code chunk number 11: zooreg2 +################################################### +zr1 <- zr1[-c(3, 5)] +zr1 +class(zr1) +frequency(zr1) + + +################################################### +### code chunk number 12: zooreg1b +################################################### +zooreg(1:5, start = as.Date("2005-01-01")) + + +################################################### +### code chunk number 13: zooreg3 +################################################### +is.regular(zr1) +is.regular(zr1, strict = TRUE) + + +################################################### +### code chunk number 14: zooreg4 +################################################### +zr1 <- as.zoo(zr1) +zr1 +class(zr1) +is.regular(zr1) +frequency(zr1) + + +################################################### +### code chunk number 15: zooreg5 +################################################### +as.ts(zr1) +identical(zr2, as.zoo(as.ts(zr2))) + + +################################################### +### code chunk number 16: plot1 (eval = FALSE) +################################################### +## plot(Z) + + +################################################### +### code chunk number 17: plot2 (eval = FALSE) +################################################### +## plot(Z, plot.type = "single", col = 2:4) + + +################################################### +### code chunk number 18: plot2-repeat +################################################### +plot(Z, plot.type = "single", col = 2:4) + + +################################################### +### code chunk number 19: plot1-repeat +################################################### +plot(Z) + + +################################################### +### code chunk number 20: plot3 +################################################### +plot(Z, type = "b", lty = 1:3, pch = list(Aa = 1:5, Bb = 2, Cc = 4), + col = list(Bb = 2, 4)) + + +################################################### +### code chunk number 21: plot3-repeat (eval = FALSE) +################################################### +## plot(Z, type = "b", lty = 1:3, pch = list(Aa = 1:5, Bb = 2, Cc = 4), +## col = list(Bb = 2, 4)) + + +################################################### +### code chunk number 22: rbind +################################################### +rbind(z1[5:10], z1[2:3]) + + +################################################### +### code chunk number 23: cbind +################################################### +cbind(z1, z2) + + +################################################### +### code chunk number 24: merge +################################################### +merge(z1, z2, all = FALSE) + + +################################################### +### code chunk number 25: merge2 +################################################### +merge(z1, pi, 1:10) + + +################################################### +### code chunk number 26: aggregate +################################################### +firstofmonth <- function(x) as.Date(sub("..$", "01", format(x))) +aggregate(Z, firstofmonth(index(Z)), mean) +aggregate(Z, firstofmonth, head, 1) + + +################################################### +### code chunk number 27: disaggregate +################################################### +Nile.na <- merge(as.zoo(Nile), + zoo(, seq(start(Nile)[1], end(Nile)[1], 1/4))) +head(as.zoo(Nile)) +head(na.approx(Nile.na)) +head(na.locf(Nile.na)) +head(na.spline(Nile.na)) + + +################################################### +### code chunk number 28: Ops +################################################### +z1 + z2 +z1 < z2 + + +################################################### +### code chunk number 29: cumsum +################################################### +cumsum(Z) + + +################################################### +### code chunk number 30: coredata +################################################### +coredata(z1) +coredata(z1) <- 1:10 +z1 + + +################################################### +### code chunk number 31: index +################################################### +index(z2) + + +################################################### +### code chunk number 32: index2 +################################################### +index(z2) <- index(z1) +z2 + + +################################################### +### code chunk number 33: startend +################################################### +start(z1) +end(z1) + + +################################################### +### code chunk number 34: window +################################################### +window(Z, start = as.Date("2004-03-01")) +window(Z, index = index(Z)[5:8], end = as.Date("2004-03-01")) + + +################################################### +### code chunk number 35: window2 +################################################### +window(z1, end = as.POSIXct("2004-02-01")) <- 9:5 +z1 + + +################################################### +### code chunk number 36: lagdiff +################################################### +lag(z1, k = -1) +merge(z1, lag(z1, k = 1)) +diff(z1) + + +################################################### +### code chunk number 37: coercion +################################################### +as.data.frame(Z) + + +################################################### +### code chunk number 38: na +################################################### +z1[sample(1:10, 3)] <- NA +z1 +na.omit(z1) +na.contiguous(z1) +na.approx(z1) +na.approx(z1, 1:NROW(z1)) +na.spline(z1) +na.locf(z1) + + +################################################### +### code chunk number 39: rollapply +################################################### +rollapply(Z, 5, sd) +rollapply(Z, 5, sd, fill = NA, align = "left") + + +################################################### +### code chunk number 40: rollmean +################################################### +rollmean(z2, 5, fill = NA) + + +################################################### +### code chunk number 41: strucchange1 +################################################### +library("strucchange") +library("DAAG") +data("fruitohms") +ocus <- gefp(ohms ~ 1, order.by = ~ juice, data = fruitohms) + + +################################################### +### code chunk number 42: strucchange2 +################################################### +plot(ocus) + + +################################################### +### code chunk number 43: tseries1 (eval = FALSE) +################################################### +## library("tseries") +## MSFT <- get.hist.quote(instrument = "MSFT", start = "2001-01-01", +## end = "2004-09-30", origin = "1970-01-01", retclass = "ts") + + +################################################### +### code chunk number 44: tseries1a +################################################### +if(online) { + MSFT <- get.hist.quote("MSFT", start = "2001-01-01", + end = "2004-09-30", origin = "1970-01-01", retclass = "ts") + save(MSFT, file = "MSFT.rda", compress = TRUE) +} else { + load("MSFT.rda") +} + + +################################################### +### code chunk number 45: tseries2 +################################################### +MSFT <- as.zoo(MSFT) +index(MSFT) <- as.Date(index(MSFT)) +MSFT <- na.omit(MSFT) + + +################################################### +### code chunk number 46: tseries3 +################################################### +MSFT <- as.zoo(MSFT) + + +################################################### +### code chunk number 47: tseries3 +################################################### +plot(diff(log(MSFT))) + + +################################################### +### code chunk number 48: timeDate2 +################################################### +library("timeDate") +z2td <- zoo(coredata(z2), timeDate(index(z2), FinCenter = "GMT")) +z2td + + +################################################### +### code chunk number 49: yearmon1 +################################################### +zr3 <- zooreg(rnorm(9), start = as.yearmon(2000), frequency = 12) +zr3 + + +################################################### +### code chunk number 50: yearmon2 +################################################### +aggregate(zr3, as.yearqtr, mean) + + +################################################### +### code chunk number 51: yearmon3 +################################################### +as.Date(index(zr3)) +as.Date(index(zr3), frac = 1) + + +################################################### +### code chunk number 52: yearmon4 +################################################### +index(zr3) <- as.POSIXct(index(zr3)) +as.irts(zr3) + + Binary files /tmp/xZFphps19Q/r-zoo-1.7-11/inst/doc/zoo-read.pdf and /tmp/p6_J8sJim1/r-zoo-1.7-12/inst/doc/zoo-read.pdf differ diff -Nru r-zoo-1.7-11/inst/doc/zoo-read.Rnw r-zoo-1.7-12/inst/doc/zoo-read.Rnw --- r-zoo-1.7-11/inst/doc/zoo-read.Rnw 2014-02-27 08:32:35.000000000 +0000 +++ r-zoo-1.7-12/inst/doc/zoo-read.Rnw 2015-03-16 13:26:56.000000000 +0000 @@ -575,7 +575,7 @@ \newpage -\section{Further comments} +\section*{Further comments} Multiple files can be read and subsequently merged. diff -Nru r-zoo-1.7-11/inst/doc/zoo.Rnw r-zoo-1.7-12/inst/doc/zoo.Rnw --- r-zoo-1.7-11/inst/doc/zoo.Rnw 2014-02-27 08:32:35.000000000 +0000 +++ r-zoo-1.7-12/inst/doc/zoo.Rnw 2015-03-16 13:26:56.000000000 +0000 @@ -191,7 +191,7 @@ vectors of classes \code{"Date"}, \code{"POSIXct"} or \code{"times"} from package \pkg{chron} and \code{"timeDate"} in \pkg{timeDate}. Because not all required methods used to be available for \code{"timeDate"} in older -versions of \pkg{fCalendar}, Section~\ref{sec:fCalendar} has a rather outdated example how +versions of \pkg{fCalendar}, Section~\ref{sec:timeDate} has a rather outdated example how to provide such methods so that \code{"zoo"} objects work with \code{"timeDate"} indexes. To achieve this independence of the index class, new generic functions for ordering (\code{ORDER()}) and value matching (\code{MATCH()}) are introduced @@ -220,7 +220,8 @@ @ and one with a sine wave <>= -z2.index <- as.POSIXct(paste(2004, rep(1:2, 5), sample(1:28, 10), sep = "-")) +z2.index <- as.POSIXct(paste(2004, rep(1:2, 5), sample(1:28, 10), + sep = "-")) z2.data <- sin(2*1:10/pi) z2 <- zoo(z2.data, z2.index) @ @@ -436,7 +437,8 @@ <> @ <>= -plot(Z, type = "b", lty = 1:3, pch = list(Aa = 1:5, Bb = 2, Cc = 4), col = list(Bb = 2, 4)) +plot(Z, type = "b", lty = 1:3, pch = list(Aa = 1:5, Bb = 2, Cc = 4), + col = list(Bb = 2, 4)) @ \caption{\label{fig:plot13} Examples of multiple panel plots} \end{center} @@ -540,10 +542,12 @@ quarterly series, convert it to a \code{"zoo} class series, insert intermediate quarterly points containing \code{NA} values and then fill the \code{NA} values using \code{na.approx}, \code{na.locf} -or \code{na.spline}: +or \code{na.spline}. (More details on \code{NA} handling in general can be found +in Section~\ref{sec:NA}.) <>= -Nile.na <- merge(as.zoo(Nile), zoo(, seq(start(Nile)[1], end(Nile)[1], 1/4))) +Nile.na <- merge(as.zoo(Nile), + zoo(, seq(start(Nile)[1], end(Nile)[1], 1/4))) head(as.zoo(Nile)) head(na.approx(Nile.na)) head(na.locf(Nile.na)) @@ -684,16 +688,16 @@ \subsection[NA handling]{\code{NA} handling} \label{sec:NA} -Four methods for dealing with \code{NA}s (missing observations) -in the observations are applicable to \code{"zoo"} objects: -\code{na.omit}, \code{na.contiguous}, \code{na.approx} and \code{na.locf}. +A wide range of methods for dealing with \code{NA}s (missing observations) +in the observations are applicable to \code{"zoo"} objects including +\code{na.omit}, \code{na.contiguous}, \code{na.approx}, \code{na.spline}, and \code{na.locf} among others. \code{na.omit}---or its default method to be more precise---returns a \code{"zoo"} object with incomplete observations removed. \code{na.contiguous} extracts the longest consecutive stretch of non-missing values. Furthermore, new generic functions -\code{na.approx} and \code{na.locf} and corresponding default methods are introduced in \pkg{zoo}. -The former replaces \code{NA}s by linear interpolation (using the -function \code{approx}) and the name of the latter +\code{na.approx}, \code{na.spline}, and \code{na.locf} and corresponding default methods are introduced in \pkg{zoo}. +The former two replace \code{NA}s by interpolation (using the +function \code{approx} and \code{spline}, respectively) and the name of the latter stands for \underline{l}ast \underline{o}bservation \underline{c}arried \underline{f}orward. It replaces missing observations by the most recent non-\code{NA} prior to it. Leading \code{NA}s, which cannot be replaced @@ -706,13 +710,18 @@ na.contiguous(z1) na.approx(z1) na.approx(z1, 1:NROW(z1)) +na.spline(z1) na.locf(z1) @ -As the above example illustrates, \code{na.approx} uses by default +As the above example illustrates, \code{na.approx} (and also \code{na.spline}) use by default the underlying time scale for interpolation. This can be changed, e.g., to an equidistant spacing, by setting the second argument of -\code{na.approx}. +\code{na.approx}. Furthermore, a different output time index can be supplied as well. + +In addition to the methods discussed above, there are also other methods +for dealing with missing values in \pkg{zoo} such as \code{na.aggregate}, +\code{na.fill}, \code{na.trim}, and \code{na.StructTS}. \subsection{Rolling functions} \label{sec:rolling} diff -Nru r-zoo-1.7-11/inst/include/zoo.h r-zoo-1.7-12/inst/include/zoo.h --- r-zoo-1.7-11/inst/include/zoo.h 1970-01-01 00:00:00.000000000 +0000 +++ r-zoo-1.7-12/inst/include/zoo.h 2015-03-15 20:26:52.000000000 +0000 @@ -0,0 +1,20 @@ +/* +Header file for using internal C-level facilities +provided by zoo. + +This is not 100% designed for end users, so +any user comments and bug reports are very +welcomed. + +Copyright Jeffrey A. Ryan 2010 +*/ + +#include +#include + +#ifndef _Zoo +#define _Zoo + +SEXP zoo_lag (SEXP x, SEXP _k, SEXP _pad); +SEXP zoo_coredata (SEXP x, SEXP copyAttr); +#endif diff -Nru r-zoo-1.7-11/man/na.StructTS.Rd r-zoo-1.7-12/man/na.StructTS.Rd --- r-zoo-1.7-11/man/na.StructTS.Rd 2011-07-19 14:59:55.000000000 +0000 +++ r-zoo-1.7-12/man/na.StructTS.Rd 2015-03-16 13:24:08.000000000 +0000 @@ -30,9 +30,9 @@ \examples{ -z <- zooreg(rep(10 * seq(4), each = 4) + rep(c(3, 1, 2, 4), times = 4), +z <- zooreg(rep(10 * seq(8), each = 4) + rep(c(3, 1, 2, 4), times = 8), start = as.yearqtr(2000), freq = 4) -z[10] <- NA +z[25] <- NA zout <- na.StructTS(z) diff -Nru r-zoo-1.7-11/man/plot.zoo.Rd r-zoo-1.7-12/man/plot.zoo.Rd --- r-zoo-1.7-11/man/plot.zoo.Rd 2011-07-19 14:59:55.000000000 +0000 +++ r-zoo-1.7-12/man/plot.zoo.Rd 2014-09-02 10:56:36.000000000 +0000 @@ -214,6 +214,29 @@ srt = -90, xpd = TRUE, col = "blue") par(opar) + +## another plot with left and right axes +## modified from https://stat.ethz.ch/pipermail/r-help/2014-May/375293.html +d1 <- c(38.2, 18.1, 83.2, 42.7, 22.8, 48.1, 81.8, 129.6, 52.0, 110.3) +d2 <- c(2.2, 0.8, 0.7, 1.6, 0.9, 0.9, 1.1, 2.8, 5.1, 2.1) +z1 <- zooreg(d1, start = as.POSIXct("2013-01-01 00:00:01"), frequency = 0.0000006) +z2 <- zooreg(d2, start = as.POSIXct("2013-01-01 00:00:20"), frequency = 0.0000006) +zt <- zooreg(rnorm(1050), start = as.POSIXct("2013-01-01 00:00:01"), frequency = 0.00007) +z <- merge(zt, z1, z2, all = TRUE) +z <- na.spline(z[,2:3], na.rm = FALSE) +## function to round up to a number divisible by n (2011 by Owen Jones) +roundup <- function(x, n) ceiling(ceiling(x)/n) * n +## plot how to match secondary y-axis ticks to primary ones +plot(z$z1, ylim = c(0, signif(max(na.omit(z$z1)), 2)), xlab = "") +## use multiplication for even tick numbers and fake sekondary y-axis +max.yl <- roundup(max(na.omit(z$z2)), par("yaxp")[3]) +multipl.yl <- max(na.omit(z$z2)) / max.yl +multipl.z2 <- signif(max(na.omit(z$z1) * 1.05), 2)/max.yl +lines(z$z2 * multipl.z2, lty = 2) +at4 <- axTicks(4) +axis(4, at = at4, seq(0, max.yl, length.out = par("yaxp")[3] + 1)) + + # automatically placed point labels \dontrun{ library("maptools") @@ -282,5 +305,13 @@ tkexamp(plot(z), tke.test1, plotloc = "top") } +# setting ylim on a multi-panel plot - 2nd panel y axis range is 1-50 +data("anscombe", package = "datasets") +ans6 <- zoo(anscombe[, 1:6]) +screens <- c(1, 1, 2, 2, 3, 3) +ylim <- unname(tapply(as.list(ans6), screens, range)) +ylim[[2]] <- 1:50 # or ylim[[2]] <- c(1, 50) +plot(ans6, screens = screens, ylim = ylim) + } \keyword{ts} diff -Nru r-zoo-1.7-11/man/read.zoo.Rd r-zoo-1.7-12/man/read.zoo.Rd --- r-zoo-1.7-11/man/read.zoo.Rd 2014-01-05 19:00:13.000000000 +0000 +++ r-zoo-1.7-12/man/read.zoo.Rd 2014-08-30 23:28:38.000000000 +0000 @@ -94,14 +94,25 @@ to the index, \code{FUN} can be specified and is applied to the first column. To process the index, \code{read.zoo} calls \code{FUN} with the index as the -first argument. If \code{FUN} is not specified then if there are multiple -index columns they are pasted together with a space between each. Using the -index column or pasted index column: 1. If \code{tz} is specified then the -index column is converted to \code{POSIXct}. 2. If \code{format} is specified -then the index column is converted to \code{Date}. 3. Otherwise, a heuristic -attempts to decide among \code{"numeric"}, \code{"Date"} and \code{"POSIXct"}. -If \code{format} and/or \code{tz} is specified then they are passed to the -conversion function as well. +first argument. If \code{FUN} is not specified, the following default is employed: + +(a) If \code{file} is a data frame with a single +index column that appears to be a time index already, then \code{FUN = identity} is used. +The conditions for a readily produced time index are: It is not \code{character} or +\code{factor} (and the arguments \code{tz} and \code{format} must not be specified). + +(b) If the conditions from (a) do not hold then the following strategy is used. +If there are multiple index columns they are pasted together with a space between each. +Using the (pasted) index column: (1) If \code{tz} is specified then the +index column is converted to \code{POSIXct}. (2) If \code{format} is specified +then the index column is converted to \code{Date}. (3) Otherwise, a heuristic +attempts to decide between \code{"numeric"}, \code{"POSIXct"}, and \code{"Date"} by +trying them in that order (which may not always succeed though). By default, +only the standard date/time format is used. Hence, supplying \code{format} and/or \code{tz} +is necessary if some date/time format is used that is not the default. And even +if the default format is appropriate for the index, explicitly supplying +\code{FUN} or at least \code{format} and/or \code{tz} typically leads to more +reliable results than the heuristic. If \code{regular} is set to \code{TRUE} and the resulting series has an underlying regularity, it is coerced to a \code{"zooreg"} series. @@ -143,8 +154,35 @@ \seealso{\code{\link{zoo}}} \examples{ +## this manual page provides a few typical examples, many more cases +## are covered in vignette("zoo-read", package = "zoo") + +## read text lines with a single date column +Lines <- "2013-12-24 2 +2013-12-25 3 +2013-12-26 8" +read.zoo(text = Lines, FUN = as.Date) # explicit coercion +read.zoo(text = Lines, format = "\%Y-\%m-\%d") # same +read.zoo(text = Lines) # same, via heuristic + +## read text lines with date/time in separate columns +Lines <- "2013-11-24 12:41:21 2 +2013-12-25 12:41:22.25 3 +2013-12-26 12:41:22.75 8" +read.zoo(text = Lines, index = 1:2, + FUN = paste, FUN2 = as.POSIXct) # explicit coercion +read.zoo(text = Lines, index = 1:2, tz = "") # same +read.zoo(text = Lines, index = 1:2) # same, via heuristic + +## read directly from a data.frame (artificial and built-in BOD) +dat <- data.frame(date = paste("2000-01-", 10:15, sep = ""), + a = sin(1:6), b = cos(1:6)) +read.zoo(dat) +data("BOD", package = "datasets") +read.zoo(BOD) + \dontrun{ -## See also vignette("zoo-read", package = "zoo") for more examples +## descriptions of typical examples ## turn *numeric* first column into yearmon index ## where number is year + fraction of year represented by month @@ -182,6 +220,9 @@ ## and no headers. T appears literally. Requires chron 2.3-22 or later. z <- read.zoo("foo.csv", FUN = as.chron) +# read in all csv files in the current directory and merge them +read.zoo(Sys.glob("*.csv"), header = TRUE, sep = ",") + # We use "NULL" in colClasses for those columns we don't need but in # col.names we still have to include dummy names for them. Of what # is left the index is the first three columns (1:3) which we convert @@ -206,22 +247,8 @@ FUN = function(h, m, s) times(paste(h, m, s, sep = ":")), FUN2 = function(tt) trunc(tt, "00:00:05"), aggregate = mean) - -## omit the read.table() phase and directly supply a data.frame -dat <- data.frame(date = paste("2000-01-", 10:15, sep = ""), a = rnorm(6), b = 1:6) -z <- read.zoo(dat) - -## using built-in data frame BOD -read.zoo(BOD) - -read.zoo(BOD, FUN = as.Date) - -read.zoo(BOD[c(1:6, 1), ], aggregate = mean) - -# read in all csv files in the current directory and merge them -read.zoo(Sys.glob("*.csv"), header = TRUE, sep = ",") - } + } \keyword{ts} diff -Nru r-zoo-1.7-11/man/rollapply.Rd r-zoo-1.7-12/man/rollapply.Rd --- r-zoo-1.7-11/man/rollapply.Rd 2011-07-19 14:59:55.000000000 +0000 +++ r-zoo-1.7-12/man/rollapply.Rd 2014-08-29 00:28:52.000000000 +0000 @@ -20,9 +20,10 @@ \arguments{ \item{data}{the data to be used (representing a series of observations).} \item{width}{numeric vector or list. In the simplest case this is an integer - specifying the window width which is aligned to the original sample according - to the \code{align} argument. Alternatively, \code{width} can be a list - regarded as offsets compared to the current time, see below for details.} + specifying the window width (in numbers of observations) which is aligned + to the original sample according to the \code{align} argument. Alternatively, + \code{width} can be a list regarded as offsets compared to the current + time, see below for details.} \item{FUN}{the function to be applied.} \item{\dots}{optional arguments to \code{FUN}.} \item{by}{calculate FUN at every \code{by}-th time point rather than @@ -98,6 +99,7 @@ rollmean(z2, 3) # same rollapply(z2, 3, (mean)) # does not use rollmean + ## rolling regression: ## set up multivariate zoo series with ## number of UK driver deaths and lags 1 and 12 @@ -117,6 +119,21 @@ ## and after the seatbelt legislation change in Jan 1983 plot(rr) + +## rolling mean by time window (e.g., 3 days) rather than +## by number of observations (e.g., when these are unequally spaced): +# +## - test data +tt <- as.Date("2000-01-01") + c(1, 2, 5, 6, 7, 8, 10) +z <- zoo(seq_along(tt), tt) +## - fill it out to a daily series, zm, using NAs +## using a zero width zoo series g on a grid +g <- zoo(, seq(start(z), end(z), "day")) +zm <- merge(z, g) +## - 3-day rolling mean +rollapply(zm, 3, mean, na.rm = TRUE, fill = NA) + + ## different values of rule argument z <- zoo(c(NA, NA, 2, 3, 4, 5, NA)) rollapply(z, 3, sum, na.rm = TRUE) diff -Nru r-zoo-1.7-11/man/zoo.Rd r-zoo-1.7-12/man/zoo.Rd --- r-zoo-1.7-11/man/zoo.Rd 2013-04-06 10:48:13.000000000 +0000 +++ r-zoo-1.7-12/man/zoo.Rd 2014-08-29 00:28:52.000000000 +0000 @@ -34,6 +34,8 @@ \alias{quantile.zoo} \alias{rev.zoo} \alias{transform.zoo} +\alias{ifelse.zoo} +\alias{dim<-.zoo} \alias{index2char} \alias{index2char.default} @@ -42,8 +44,6 @@ \alias{head.ts} \alias{tail.ts} -\alias{ifelse.zoo} - \title{Z's Ordered Observations} \description{ \code{zoo} is the creator for an S3 class of indexed diff -Nru r-zoo-1.7-11/MD5 r-zoo-1.7-12/MD5 --- r-zoo-1.7-11/MD5 2014-02-27 10:46:03.000000000 +0000 +++ r-zoo-1.7-12/MD5 2015-03-16 18:13:59.000000000 +0000 @@ -1,40 +1,40 @@ -e786634f56e22797abefdc1afac17074 *DESCRIPTION -65ec3fcf6203eb258e61b412390173f2 *NAMESPACE -118813ce4599e4f748708f05e6ecd7d4 *NEWS -0d3a237bf61d1881c7ebebd69c3b30c9 *R/MATCH.R -58526e3e16531c683e1b40a3d08c3fc5 *R/ORDER.R +83c24d4997cc1bec104fcf499f5f0766 *DESCRIPTION +4a5d5c2ecbc7a8e235a5f602c96a2114 *NAMESPACE +07aaeb3d8d3c9d04bf39ee1de9090243 *NEWS +822620e8a24658c3e55f6593b8d66c78 *R/MATCH.R +3eebd5fe3394080789fedfea3a45e3ab *R/ORDER.R 9015ff069b28219b6dc44505641d249c *R/Ops.zoo.R 407a111f9bd9245db5aeb1b999df2499 *R/aggregate.zoo.R 9b2752b85b382ef96a6f28663170491e *R/as.Date.R 93ff2d240541d0aa3588d410eb235699 *R/as.Date.ts.R -117e4d69a8786865fca6ede2b09c6e19 *R/as.zoo.R -aa948827212d6c0e3834f6eef7b6e82a *R/as.zoo.tis.R +d5daab2a9d761992ad12214655f2cd0f *R/as.zoo.R +62c1bf87a7380c654f17b1b8ed71efc6 *R/as.zoo.tis.R 5413af6851aed20d8fa81a8f7a895737 *R/barplot.zoo.R -eb9ae996db706251ae065c6b77877cde *R/coredata.R -b199ef2867a33946c12cb0b3438604d8 *R/ggplot2.zoo.R -2e834ac5e827d8becce70582dc1949aa *R/index.R +5af291cb99c193b4db3fc89ac9a59cff *R/coredata.R +185a8f43b9cd661c3c9e33e7b320f0e4 *R/ggplot2.zoo.R +f0355f8f053e7a066d733b73e6771e5b *R/index.R e0b9e9a919725d282d7b4e608e42a364 *R/index2char.R e9e788521e48a8c3eea367971cb9633e *R/is.regular.R faa14832f6dd3b8e4920e3dea63834ee *R/merge.zoo.R -d3d3379645412d1da0c24bcb49291583 *R/na.StructTS.R +7564a94e7eb8117617e4433e69f0b50b *R/na.StructTS.R 4e8c25337f2e1891e0939ebf2e6b0138 *R/na.aggregate.R 700075b9d6c2a1b0922d138fd5aeb9fa *R/na.approx.R -468b2282a3260ea7b1790e5b047b28e4 *R/na.fill.R +54d99847d13a735d2a9a8da3ec88dca3 *R/na.fill.R dd2e1368324e6b8ee8179d9c4b570123 *R/na.locf.R d912001ad34a995582e851f1b471c0e9 *R/na.spline.R 53f4edd246db8ca0c69567c5fb1dad61 *R/na.trim.R -ae059d28cc5c0b7cc3fd6bce24b9bdeb *R/plot.zoo.R -d1a70c38b42b9e8a0429c529ec6cbd99 *R/read.zoo.R +5f571fb640a9793b7463c687f0a9041f *R/plot.zoo.R +ae9d12cbecd5b676e501666269f42aea *R/read.zoo.R 37a3a11361580562ea0e830fa4b09958 *R/rollapply.R 80350d05a3bd71276845a1ff9cb890b5 *R/rollmean.R 89e9c21c3558acb9e95dfab063e5c5d5 *R/window.zoo.R 94aa2ade75635c4dee7754036bce16c0 *R/xblocks.R -11685e4c3ecd80a0224386e7699988df *R/xyplot.zoo.R -c51a4fcf576ddde13d21b5f343b977ba *R/yearmon.R -5a8c3d00f0ea66d395ce0fb9a1c28877 *R/yearqtr.R -3faeca1809ffffec2774b85c89c7a649 *R/zoo.R -3070a310d50f4bfe3d0a11e6e8354dcf *R/zooreg.R -1a8b0aebd15784d2e77b54991cbd0952 *build/vignette.rds +389f742ae97c605bd2872ad2d654d41e *R/xyplot.zoo.R +08bd879767d6b11f25a2c4070b2e4506 *R/yearmon.R +3396899c1d53d3906ee3064391a16922 *R/yearqtr.R +141d8d985e98faa2f7cbffcd647f51ff *R/zoo.R +b3bea0ff127e8f8027d713e7e830fe82 *R/zooreg.R +e8e135c7c0ac40deb7579eeb1eb6c300 *build/vignette.rds beb8720082847566abaa78c65ee97815 *demo/00Index 59d8732e0de2f3cb82141eb8d97a2477 *demo/zoo-overplot.R caf8cbff3ce975a11a2457d4b9b09ef6 *inst/CITATION @@ -47,18 +47,20 @@ 8ab6ae33767b9f99c8158192e12832c1 *inst/doc/sunw.rda e90680abb6a7cd9bd8de0e07667711b7 *inst/doc/zoo-design.R 5051eb1d34cd0d183e2d84449912c9f8 *inst/doc/zoo-design.Rnw -a2ec57fcbd2f94b56dd4bc67f4cee367 *inst/doc/zoo-design.pdf +ee5ce1ea006b23dd0937eebad0c2b4cf *inst/doc/zoo-design.pdf 45323f04a5e08dc2af3187376b1b0d90 *inst/doc/zoo-faq.R 598475df10385cb019bd104c3e23bbca *inst/doc/zoo-faq.Rnw -c8a1bc1ecd6e0510e199c09270208a55 *inst/doc/zoo-faq.pdf -026bf98b7f811d1487b7927b1caf46db *inst/doc/zoo-quickref.R -8ec9c8c8b5a27088b6a4603f05e8822e *inst/doc/zoo-quickref.Rnw -3b892b9a1782b30a9e99d1444a16db64 *inst/doc/zoo-quickref.pdf +47d5a3627bd2753be82048c283bdb0e8 *inst/doc/zoo-faq.pdf +83677e22279048b6ae92d0eb97825807 *inst/doc/zoo-quickref.R +7b674cd4ed0ec2839e83ed7d56be11d3 *inst/doc/zoo-quickref.Rnw +a62f229d3388514e0c0c045a99dd1230 *inst/doc/zoo-quickref.pdf 7d6ae67bb66889b140f813a41de176ca *inst/doc/zoo-read.R -4bf64e1306382fa9adec698dca911648 *inst/doc/zoo-read.Rnw -859829a114182a4822fb09919e82283b *inst/doc/zoo-read.pdf -eb337d4629019c86db356af4cbbbeaa5 *inst/doc/zoo.Rnw -99523afb0c7478b500b8de6981c83531 *inst/doc/zoo.pdf +b250829a07529fce7fa4fa5a9ebf8185 *inst/doc/zoo-read.Rnw +da83be519b96c6558ee1b9a46828c8d5 *inst/doc/zoo-read.pdf +a8cbc1c727a9799f10f08cd185c94733 *inst/doc/zoo.R +62a726d8b09880de357f4faffbcaa19e *inst/doc/zoo.Rnw +4d6f4a9b0f333d0534fcac65109046f8 *inst/doc/zoo.pdf +dd2909911733f11d02837283e885402e *inst/include/zoo.h b9399dea40883cbabe28389558bea5b1 *man/MATCH.Rd ce5614980ae640df7c8388f72de3a0ca *man/ORDER.Rd 7d9d99d22e0e55574b9f982f7690ba7f *man/aggregate.zoo.Rd @@ -71,32 +73,33 @@ c97b5855503b079c6bb4ec2e47764ede *man/lag.zoo.Rd 2a40905ca067abf2ac4b679c6e12748a *man/make.par.list.Rd c74dd08722ed8c81c46a9bd01d84f2c6 *man/merge.zoo.Rd -280a0fa48fe9b99f66956fe4931de5f7 *man/na.StructTS.Rd +3f9b9d7e4aac1baf4cbee88d38fabd82 *man/na.StructTS.Rd d2c2255460d224a4a7c332f5c03cce4c *man/na.aggregate.Rd 1f4c887009f3a98d028904a1240bfe4d *man/na.approx.Rd 812e67ad96f11c0b6ac87f1c1d447417 *man/na.fill.Rd b563566d30230fec9c5d1e8fa6e507d0 *man/na.locf.Rd 72f8fedd1165de8c679ebbedc552c04b *man/na.trim.Rd -b58440cedf693183602e7c46bf6edee0 *man/plot.zoo.Rd -5c63f073288592c784d409e8817ed750 *man/read.zoo.Rd -94d85c7ca6fa7207c457a39645ca08ef *man/rollapply.Rd +81419b221f4dbc4514fa7eac56b3802e *man/plot.zoo.Rd +0c12ed17b78be6f76ab2eef2e04bf655 *man/read.zoo.Rd +27b60ea8f14b14c4e716489fed4c5f2d *man/rollapply.Rd 49592bdb8f27d2c81d3280295522cec2 *man/rollmean.Rd d0cbd403034400d2df9a4d55d38e815e *man/window.zoo.Rd b01d46391c525d1510c69c3bcbe70744 *man/xblocks.Rd eb33e870fccca3e5aac3d1ac198e542b *man/xyplot.zoo.Rd fbcc950e453e5395780e03914461d0d5 *man/yearmon.Rd 956e061afb87e8f9e633e9b39262929a *man/yearqtr.Rd -a0ad96b1d8212a88749a5f4e5996defb *man/zoo.Rd +44c2e6fd0022606164ea6aee78d7c658 *man/zoo.Rd 28545accfae55aba893bb6ef4ea51a18 *man/zooreg.Rd +3f03da795dd26373156bddc78d41e95d *src/Makevars +3f03da795dd26373156bddc78d41e95d *src/Makevars.win aa5bac3353d00be05a9bbabef9696bc8 *src/coredata.c -0292cb3c50739e490289729872c22507 *src/init.c -29d9b7988cf840ee7adb20adfca75a92 *src/lag.c -dd2909911733f11d02837283e885402e *src/zoo.h -8a89673ce71a7cd766d6e438aab7a899 *tests/Examples/zoo-Ex.Rout.save +e2b10fd2e074ee926a47c9eeee2946ba *src/init.c +19f2b7322772ed5c1af0bc561e49399e *src/lag.c +c72b344aefa3ddbc32b977174e9a1764 *tests/Examples/zoo-Ex.Rout.save b512f313e67b56e595e06e7854eeb49e *tests/as.Date.R 17704f5fcab3940be50e3b595b905c0d *tests/as.Date.Rout.save -240ad939b84e1d2db4a7fc231d52ab40 *tests/bugfixes.R -213a8b59905d08f7b9fe612d8e878836 *tests/bugfixes.Rout.save +3208e41199e2d233f5d1272f58d0fd9f *tests/bugfixes.R +0cbfa36f15b7cfae60c5278ea06aed68 *tests/bugfixes.Rout.save 747601a7627f9f4d3166c1e80812fe75 *tests/vignette-zoo-quickref.R c9fb01c668e21d25eda96d0c61018758 *tests/vignette-zoo-quickref.Rout.save 720280779ba1db456681dbb28dd74c43 *tests/vignette-zoo.R @@ -107,10 +110,10 @@ 8ab6ae33767b9f99c8158192e12832c1 *vignettes/sunw.rda 5051eb1d34cd0d183e2d84449912c9f8 *vignettes/zoo-design.Rnw 598475df10385cb019bd104c3e23bbca *vignettes/zoo-faq.Rnw -8ec9c8c8b5a27088b6a4603f05e8822e *vignettes/zoo-quickref.Rnw -4bf64e1306382fa9adec698dca911648 *vignettes/zoo-read.Rnw +7b674cd4ed0ec2839e83ed7d56be11d3 *vignettes/zoo-quickref.Rnw +b250829a07529fce7fa4fa5a9ebf8185 *vignettes/zoo-read.Rnw 6ad1f9d56475d122f628fd147278c38e *vignettes/zoo-refcard-raw.tex ecc325b9e45907aa10e771f4cd578a2f *vignettes/zoo-refcard.pdf ef7fd243ec57bc81c59c22bad0214916 *vignettes/zoo-refcard.tex -eb337d4629019c86db356af4cbbbeaa5 *vignettes/zoo.Rnw -76d25c4dcd6fdf3973e49f0e21c08072 *vignettes/zoo.bib +62a726d8b09880de357f4faffbcaa19e *vignettes/zoo.Rnw +f70f20d30cd9481f5ee56793fc4e3ee2 *vignettes/zoo.bib diff -Nru r-zoo-1.7-11/NAMESPACE r-zoo-1.7-12/NAMESPACE --- r-zoo-1.7-11/NAMESPACE 2013-07-24 15:06:53.000000000 +0000 +++ r-zoo-1.7-12/NAMESPACE 2014-11-11 18:47:25.000000000 +0000 @@ -167,10 +167,12 @@ S3method("cycle", "zoo") S3method("deltat", "zoo") S3method("diff", "zoo") + S3method("dim<-", "zoo") S3method("end", "zoo") S3method("frequency", "zoo") S3method("frequency<-", "zoo") S3method("head", "zoo") + S3method("ifelse", "zoo") S3method("index", "zoo") S3method("index<-", "zoo") S3method("is.regular", "zoo") @@ -200,6 +202,7 @@ S3method("rollmax", "zoo") S3method("rollmean", "zoo") S3method("rollmedian", "zoo") + S3method("rollsum", "zoo") S3method("scale", "zoo") S3method("split", "zoo") S3method("subset", "zoo") @@ -232,6 +235,7 @@ S3method("time<-", "zooreg") ## methods for class ts + S3method("as.Date", "ts") S3method("coredata", "ts") S3method("coredata<-", "ts") S3method("index", "ts") @@ -244,6 +248,7 @@ S3method("rollmax", "ts") S3method("rollmean", "ts") S3method("rollmedian", "ts") + S3method("rollsum", "ts") S3method("xblocks", "ts") ## methods for class irts @@ -266,6 +271,7 @@ ## methods for class yearmon S3method("-", "yearmon") + S3method("as.Date", "yearmon") S3method("Axis", "yearmon") S3method("MATCH", "yearmon") S3method("Ops", "yearmon") @@ -284,6 +290,8 @@ S3method("format", "yearmon") S3method("is.numeric", "yearmon") S3method("mean", "yearmon") + S3method("months", "yearmon") + S3method("quarters", "yearmon") S3method("print", "yearmon") S3method("range", "yearmon") S3method("summary", "yearmon") @@ -292,6 +300,7 @@ ## methods for class yearqtr S3method("-", "yearqtr") + S3method("as.Date", "yearqtr") S3method("Axis", "yearqtr") S3method("MATCH", "yearqtr") S3method("Ops", "yearqtr") @@ -310,6 +319,8 @@ S3method("format", "yearqtr") S3method("is.numeric", "yearqtr") S3method("mean", "yearqtr") + S3method("months", "yearqtr") + S3method("quarters", "yearqtr") S3method("print", "yearqtr") S3method("range", "yearqtr") S3method("summary", "yearqtr") @@ -347,11 +358,11 @@ S3method("rollmax", "default") S3method("rollmean", "default") S3method("rollmedian", "default") - S3method("rollmedian", "default") S3method("rollsum", "default") S3method("xblocks", "default") ## coercion to classes Date, list, yearmon, yearqtr, zoo, zooreg + S3method("as.Date", "numeric") S3method("as.list", "ts") S3method("as.yearmon", "date") S3method("as.yearmon", "Date") diff -Nru r-zoo-1.7-11/NEWS r-zoo-1.7-12/NEWS --- r-zoo-1.7-11/NEWS 2014-02-21 00:35:36.000000000 +0000 +++ r-zoo-1.7-12/NEWS 2015-03-05 21:56:54.000000000 +0000 @@ -1,3 +1,25 @@ +Changes in Version 1.7-12 + + o read.zoo with a data.frame argument now defaults to FUN = identity + if the index.column is not character or factor. See ?read.zoo for + additional details. + + o Added a dim<- method that checks whether the new dimension value + appears to be ok and then calls the default. + + o The index<- and time<- methods now enforce that the new time index + is actually correctly ordered (suggested by Joshua Ulrich). + + o read.zoo() heuristic improved so that POSIXct rather than Date is + detected in cases like: read.zoo(text = "2010-01-01 12:05:03 88.1", + index = 1:2). + + o The fortify() method now has a col.names argument that allows to set + (some of) the column names of the resulting data.frame. + + o Various small bug fixes and enhancements. + + Changes in Version 1.7-11 o Extended the license from "GPL-2" to "GPL-2 | GPL-3". diff -Nru r-zoo-1.7-11/R/as.zoo.R r-zoo-1.7-12/R/as.zoo.R --- r-zoo-1.7-11/R/as.zoo.R 2012-01-23 20:33:33.000000000 +0000 +++ r-zoo-1.7-12/R/as.zoo.R 2015-01-27 22:36:31.000000000 +0000 @@ -25,7 +25,6 @@ as.zoo.fts <- function(x, ...) { - stopifnot(require("fts")) zoo(as.matrix(x), attr(x, "dates")) } @@ -44,35 +43,23 @@ # as.mcmc.default can handle other direction as.zoo.mcmc <- function(x, ...) { - stopifnot(require("coda")) as.zoo(as.ts(x, ...)) } as.zoo.timeSeries <- function(x, ...) { - stopifnot(require("timeSeries")) zoo(as.matrix(x), timeSeries::time(x), ...) } as.zoo.xts <- function(x, ...) { - stopifnot(require("xts")) zoo(coredata(x), order.by = index(x), ...) } as.zooreg.xts <- function(x, frequency = NULL, ...) { - stopifnot(require("xts")) as.zooreg(as.zoo(x, ...), frequency = frequency) } as.zoo.zoo <- function(x, ...) x -## This should be in its now. -## as.its.zoo <- function(x) { -## stopifnot(require("its")) -## index <- index(x) -## stopifnot(inherits(index, "POSIXct")) -## its(coredata(x), index) -## } - as.vector.zoo <- function(x, mode = "any") as.vector(as.matrix(x), mode = mode) @@ -84,7 +71,7 @@ colnames(y) <- if (length(colnames(x)) > 0) colnames(x) else { - lab <- deparse(substitute(x)) + lab <- deparse(substitute(x), width.cutoff = 100L, nlines = 1L) if (NCOL(x) == 1) lab else paste(lab, 1:NCOL(x), sep = ".") @@ -104,7 +91,7 @@ colnames(y) <- if (length(colnames(x)) > 0) colnames(x) else { - lab <- deparse(substitute(x)) + lab <- deparse(substitute(x), width.cutoff = 100L, nlines = 1L) if (NCOL(x) == 1) lab else paste(lab, 1:NCOL(x), sep = ".") } @@ -154,9 +141,13 @@ { freq <- frequency(x) deltat <- 1/freq - # round. <- function(x) deltat * round(x/deltat) - round. <- function(x) deltat * floor(x/deltat+0.5) - tt <- round.(as.numeric(time(x))) + tt <- as.numeric(time(x)) + round. <- if(isTRUE(all.equal(c(deltat, tt), round(c(deltat, tt))))) { + function(x) floor(x + 0.5) + } else { + function(x) deltat * floor(x/deltat + 0.5) + } + tt <- round.(tt) tt2 <- round.(seq(head(tt,1), tail(tt,1), deltat)) xx <- merge(zoo(coredata(x), tt), zoo(, tt2)) ts(coredata(xx), start = tt[1], frequency = freq) diff -Nru r-zoo-1.7-11/R/as.zoo.tis.R r-zoo-1.7-12/R/as.zoo.tis.R --- r-zoo-1.7-11/R/as.zoo.tis.R 2012-01-23 20:33:33.000000000 +0000 +++ r-zoo-1.7-12/R/as.zoo.tis.R 2015-01-27 08:16:18.000000000 +0000 @@ -1,23 +1,16 @@ -as.zoo.tis <- function(x, ...) { - as.zoo(as.zooreg(x, ...)) -} - as.zoo.tis <- function(x, class = "ti", ...) { - if (class == "ti") { - as.zoo(as.zooreg(x, class = "ti", ...)) - } else if (class == "numeric") { - zoo(stripTis(x), time(ti(x), offset = 0)) - } else { - asFun <- paste("as", class, sep = ".") - zoo(stripTis(x), - do.call(asFun, list(POSIXct(ti(x), offset = 0, tz = "GMT"))), ...) - } + if (class == "ti") { + as.zoo(as.zooreg(x, class = "ti", ...)) + } else if (class == "numeric") { + zoo(tis::stripTis(x), time(tis::ti(x), offset = 0)) + } else { + asFun <- paste("as", class, sep = ".") + zoo(tis::stripTis(x), do.call(asFun, list(tis::POSIXct(tis::ti(x), offset = 0, tz = "GMT"))), ...) + } } as.zooreg.tis <- function(x, frequency = NULL, class = "ti", ...) { - if (class == "ti") - zooreg(stripTis(x), start = start(x), ...) - else - as.zooreg(as.zoo(x, class = class, ...), frequency = frequency) + if (class == "ti") zooreg(tis::stripTis(x), start = start(x), ...) + else as.zooreg(as.zoo(x, class = class, ...), frequency = frequency) } diff -Nru r-zoo-1.7-11/R/coredata.R r-zoo-1.7-12/R/coredata.R --- r-zoo-1.7-11/R/coredata.R 2012-01-23 20:33:33.000000000 +0000 +++ r-zoo-1.7-12/R/coredata.R 2015-01-27 08:17:03.000000000 +0000 @@ -31,7 +31,6 @@ coredata.its <- function(x, ...) { - stopifnot("package:its" %in% search() || require("its", quietly = TRUE)) return(x@.Data) } @@ -71,7 +70,6 @@ "coredata<-.its" <- function(x, value) { - stopifnot("package:its" %in% search() || require("its", quietly = TRUE)) stopifnot(length(x@.Data) == length(value)) dim(value) <- dim(x@.Data) x@.Data[] <- as.matrix(value) diff -Nru r-zoo-1.7-11/R/ggplot2.zoo.R r-zoo-1.7-12/R/ggplot2.zoo.R --- r-zoo-1.7-11/R/ggplot2.zoo.R 2014-01-05 19:17:15.000000000 +0000 +++ r-zoo-1.7-12/R/ggplot2.zoo.R 2015-01-27 08:16:02.000000000 +0000 @@ -30,9 +30,6 @@ autoplot.zoo <- function(object, geom = "line", facets, ...) { - ## need ggplot2 package - stopifnot(require("ggplot2")) - ## convert to data.frame (and assure correct label ## processing by fortify.zoo) lab <- deparse(substitute(object)) @@ -57,43 +54,42 @@ ## call qplot gg <- if(single | (!is.null(facets) & auto)) { - qplot(Index, Value, data = df, geom = geom, facets = facets, ...) + ylab(if(single) levels(df$Series) else "") + xlab("Index") + ggplot2::qplot(Index, Value, data = df, geom = geom, facets = facets, ...) + ggplot2::ylab(if(single) levels(df$Series) else "") + ggplot2::xlab("Index") } else { - qplot(Index, Value, data = df, group = Series, geom = geom, facets = facets, colour = Series, ...) + ylab("") + xlab("Index") + ggplot2::qplot(Index, Value, data = df, group = Series, geom = geom, facets = facets, colour = Series, ...) + ggplot2::ylab("") + ggplot2::xlab("Index") } return(gg) } facet_free <- function (facets = Series ~ ., margins = FALSE, scales = "free_y", ...) { - stopifnot(require("ggplot2")) - facet_grid(facets, margins = margins, scales = scales, ...) + ggplot2::facet_grid(facets, margins = margins, scales = scales, ...) } yearmon_trans <- function(format = "%b %Y", n = 5) { - breaks. <- function(x) as.yearmon(pretty_breaks(n)(x)) + breaks. <- function(x) as.yearmon(scales::pretty_breaks(n)(x)) format. <- function(x) format(x, format = format) scales::trans_new("yearmon", transform = as.numeric, inverse = as.yearmon, breaks = breaks., format = format.) } scale_x_yearmon <- function(..., format = "%b %Y", n = 5) { - scale_x_continuous(..., trans = yearmon_trans(format, n)) + ggplot2::scale_x_continuous(..., trans = yearmon_trans(format, n)) } scale_y_yearmon <- function(..., format = "%b %Y", n = 5) { - scale_y_continuous(..., trans = yearmon_trans(format, n)) + ggplot2::scale_y_continuous(..., trans = yearmon_trans(format, n)) } yearqtr_trans <- function(format = "%Y-%q", n = 5) { - breaks. <- function(x) as.yearqtr(pretty_breaks(n)(x)) + breaks. <- function(x) as.yearqtr(scales::pretty_breaks(n)(x)) format. <- function(x) zoo::format.yearqtr(x, format = format) scales::trans_new("yearqtr", transform = as.numeric, inverse = as.yearqtr, breaks = breaks., format = format.) } scale_x_yearqtr <- function(..., format = "%Y-%q", n = 5) { - scale_x_continuous(..., trans = yearqtr_trans(format, n)) + ggplot2::scale_x_continuous(..., trans = yearqtr_trans(format, n)) } scale_y_yearqtr <- function(..., format = "%Y-%q", n = 5) { - scale_y_continuous(..., trans = yearqtr_trans(format, n)) + ggplot2::scale_y_continuous(..., trans = yearqtr_trans(format, n)) } diff -Nru r-zoo-1.7-11/R/index.R r-zoo-1.7-12/R/index.R --- r-zoo-1.7-11/R/index.R 2010-03-31 14:18:33.000000000 +0000 +++ r-zoo-1.7-12/R/index.R 2014-08-30 21:01:19.000000000 +0000 @@ -38,6 +38,8 @@ { if(length(index(x)) != length(value)) stop("length of index vectors does not match") + if(is.unsorted(ORDER(value))) + stop("new index needs to be sorted") attr(x, "index") <- value return(x) } @@ -46,6 +48,8 @@ { if(length(index(x)) != length(value)) stop("length of index vectors does not match") + if(is.unsorted(ORDER(value))) + stop("new index needs to be sorted") ## check whether new index still conforms with ## frequency, if not: drop frequency diff -Nru r-zoo-1.7-11/R/MATCH.R r-zoo-1.7-12/R/MATCH.R --- r-zoo-1.7-11/R/MATCH.R 2010-03-31 14:18:33.000000000 +0000 +++ r-zoo-1.7-12/R/MATCH.R 2015-01-27 08:17:27.000000000 +0000 @@ -5,12 +5,10 @@ match(x, table, nomatch = nomatch, ...) MATCH.timeDate <- function(x, table, nomatch = NA, ...) { - stopifnot(require("timeDate")) match(as.POSIXct(x), as.POSIXct(table), nomatch = nomatch, ...) } -MATCH.times <- function(x, table, nomatch = NA, units = "sec", - eps = 1e-10, ...) { +MATCH.times <- function(x, table, nomatch = NA, units = "sec", eps = 1e-10, ...) { match(trunc(x, units, eps), trunc(table, units, eps), nomatch = nomatch, ...) } diff -Nru r-zoo-1.7-11/R/na.fill.R r-zoo-1.7-12/R/na.fill.R --- r-zoo-1.7-11/R/na.fill.R 2013-02-04 07:24:20.000000000 +0000 +++ r-zoo-1.7-12/R/na.fill.R 2014-08-29 01:33:20.000000000 +0000 @@ -71,9 +71,11 @@ keep <- setdiff(keep, intersect(which(!ix), wrng)) } if (length(fill[[3]]) == 0) keep <- unique(pmin(wx.max, keep)) - object[keep, , drop = is.null(dim(object))] + return(object[keep, , drop = is.null(dim(object))]) + } else if(length(fill)) { + object[is.na(object)] <- fill + return(object) } - } na.fill.default <- function(object, fill, ix, ...) { diff -Nru r-zoo-1.7-11/R/na.StructTS.R r-zoo-1.7-12/R/na.StructTS.R --- r-zoo-1.7-11/R/na.StructTS.R 2012-01-23 20:33:33.000000000 +0000 +++ r-zoo-1.7-12/R/na.StructTS.R 2014-08-29 01:14:38.000000000 +0000 @@ -3,7 +3,6 @@ na.StructTS.ts <- function(object, ..., na.rm = FALSE, maxgap = Inf) { - print("entering ts method") na.StructTS.0 <- function(y) { yf <- y isna <- is.na(y) @@ -16,7 +15,6 @@ } na.StructTS.zoo <- function(object, ..., na.rm = FALSE, maxgap = Inf) { - print("entering zoo method") z <- na.StructTS(as.ts(object), ..., na.rm = FALSE, maxgap = maxgap) z <- as.zoo(z) time(z) <- time(object) diff -Nru r-zoo-1.7-11/R/ORDER.R r-zoo-1.7-12/R/ORDER.R --- r-zoo-1.7-11/R/ORDER.R 2010-03-31 14:18:33.000000000 +0000 +++ r-zoo-1.7-12/R/ORDER.R 2015-01-27 08:17:34.000000000 +0000 @@ -5,7 +5,6 @@ order(x, ..., na.last = na.last, decreasing = decreasing) ORDER.timeDate <- function(x, ...) { - stopifnot(require("timeDate")) order(as.POSIXct(x), ...) } diff -Nru r-zoo-1.7-11/R/plot.zoo.R r-zoo-1.7-12/R/plot.zoo.R --- r-zoo-1.7-11/R/plot.zoo.R 2013-05-22 10:18:13.000000000 +0000 +++ r-zoo-1.7-12/R/plot.zoo.R 2014-08-29 01:14:31.000000000 +0000 @@ -98,6 +98,7 @@ main.outer <- TRUE if(is.null(ylab)) ylab <- colnames(x)[!duplicated(screens)] if(is.null(ylab)) ylab <- paste("Series", which(!duplicated(screens))) + if(is.call(ylab)) ylab <- as.expression(ylab) ylab <- rep(ylab, length.out = ngraph) lty <- rep(lty, length.out = nser) lwd <- rep(lwd, length.out = nser) @@ -153,11 +154,18 @@ do.call("axis", c(list(side = y.side, xpd = NA), dots)) mtext(ylab[j], y.side, line = 3) - for(i in which(screens == levels(screens)[j])) + for(i in which(screens == levels(screens)[j])) { + ## for potential usage in panel function + series.number <- i + series.within.screen <- ave(seq_along(screens), screens, FUN = seq_along)[series.number] + + ## draw individual lines/points with panel function panel(x.index, x[, i], col = col[[i]], pch = pch[[i]], lty = lty[i], lwd = lwd[i], type = type[[i]], ...) + } } } else { if(is.null(ylab)) ylab <- deparse(substitute(x)) + if(is.call(ylab)) ylab <- as.expression(ylab) if(is.null(main)) main <- "" main.outer <- FALSE if(is.null(ylim)) ylim <- range(x, na.rm = TRUE) @@ -206,12 +214,12 @@ plot.ti <- function (x, y, xlab = "", ...) { - x <- POSIXct(x) + x <- tis::POSIXct(x) NextMethod() } points.ti <- lines.ti <- function(x, ...) { - x <- POSIXct(x) + x <- tis::POSIXct(x) NextMethod() } diff -Nru r-zoo-1.7-11/R/read.zoo.R r-zoo-1.7-12/R/read.zoo.R --- r-zoo-1.7-11/R/read.zoo.R 2012-01-23 20:33:33.000000000 +0000 +++ r-zoo-1.7-12/R/read.zoo.R 2014-08-30 22:11:10.000000000 +0000 @@ -20,6 +20,20 @@ ## read data rval <- if (is.data.frame(file)) file else read.table(file, ...) + ## if time index appears to be already processed, use FUN = identity + if (is.data.frame(file) && + length(index.column) == 1 && + !is.character(rval[[index.column]]) && + !is.factor(rval[[index.column]]) && + missing(tz) && + missing(format) && + missing(FUN)) FUN <- identity + + ## if time index is POSIXlt it is coerced to POSIXct + if (is.data.frame(file) && + length(index.column) == 1 && + inherits(rval[[index.column]], "POSIXlt")) rval[[index.column]] <- as.POSIXct(rval[[index.column]]) + # returns TRUE if a formal argument x has no default no.default <- function(x) typeof(x) %in% c("symbol", "language") @@ -79,7 +93,7 @@ else split rval2 <- if (is.null(split.)) { - rval[ , ! is.index.column, drop = drop] + rval[ , ! is.index.column, drop = FALSE] } else { split.values <- if (is.character(split) || is.finite(split)) rval[, split] @@ -94,18 +108,26 @@ if (0 %in% split.) { stop(paste("split:", split, "not found in colnames:", colnames(rval))) } - rval[,-c(if (is.finite(split.)) split. else 0, which(is.index.column)), drop = drop] + rval[,-c(if (is.finite(split.)) split. else 0, which(is.index.column)), drop = FALSE] } if(is.factor(ix)) ix <- as.character(ix) rval3 <- if(is.data.frame(rval2)) as.matrix(rval2) else if(is.list(rval2)) t(rval2) else rval2 + + if(NCOL(rval3) == 1 && drop) rval3 <- drop(rval3) + ## index transformation functions toDate <- if(missing(format) || is.null(format)) { function(x, ...) as.Date(format(x, scientific = FALSE)) } else { - function(x, format) as.Date(format(x, scientific = FALSE), format = format) + function(x, format) { + if(any(sapply(c("%H", "%M", "%S"), function(y) grepl(y, format, fixed = TRUE)))) { + warning("the 'format' appears to be for a date/time, please specify 'tz' if you want to create a POSIXct time index") + } + as.Date(format(x, scientific = FALSE), format = format) + } } toPOSIXct <- if (missing(format) || is.null(format)) { @@ -115,7 +137,7 @@ } toDefault <- function(x, ...) { - rval. <- try(toPOSIXct(x, ...), silent = TRUE) + rval. <- try(toPOSIXct(x, tz = ""), silent = TRUE) if(inherits(rval., "try-error")) rval. <- try(toDate(x), silent = TRUE) else { @@ -224,14 +246,6 @@ rval8 <- do.call(merge, rval6) - if (FALSE) { - rval8 <- if (!is.null(agg.fun)) { - f.ag <- function(z) aggregate(z, time(z), agg.fun) - rval7 <- lapply(seq_along(rval6), f.ag) - do.call(merge, rval7) - } else do.call(merge, rval6) - } - } return(rval8) diff -Nru r-zoo-1.7-11/R/xyplot.zoo.R r-zoo-1.7-12/R/xyplot.zoo.R --- r-zoo-1.7-11/R/xyplot.zoo.R 2014-02-27 08:31:29.000000000 +0000 +++ r-zoo-1.7-12/R/xyplot.zoo.R 2015-01-27 08:16:37.000000000 +0000 @@ -35,7 +35,7 @@ xyplot.tis <- function(x, data, ...) { - x <- aggregate(as.zoo(x), POSIXct, identity) + x <- aggregate(as.zoo(x), tis::POSIXct, identity) obj <- lattice::xyplot.ts(x, ...) obj$call <- match.call() obj diff -Nru r-zoo-1.7-11/R/yearmon.R r-zoo-1.7-12/R/yearmon.R --- r-zoo-1.7-11/R/yearmon.R 2013-07-24 15:08:10.000000000 +0000 +++ r-zoo-1.7-12/R/yearmon.R 2014-08-29 00:28:52.000000000 +0000 @@ -79,7 +79,7 @@ c.yearmon <- function(...) as.yearmon(do.call("c", lapply(list(...), as.numeric))) -cycle.yearmon <- function(x, ...) as.numeric(months(x)) +cycle.yearmon <- function(x, ...) round(12 * (as.numeric(x) %% 1)) + 1 format.yearmon <- function(x, format = "%b %Y", ...) { @@ -94,12 +94,12 @@ invisible(x) } -months.yearmon <- function(x, abbreviate) { - months(as.Date(x), abbreviate) +months.yearmon <- function(x, abbreviate = FALSE) { + months(as.Date(x), abbreviate = abbreviate) } -quarters.yearmon <- function(x, abbreviate) { - quarters(as.Date(x), abbreviate) +quarters.yearmon <- function(x, abbreviate = FALSE) { + quarters(as.Date(x), abbreviate = abbreviate) } "[.yearmon" <- function (x, ..., drop = TRUE) diff -Nru r-zoo-1.7-11/R/yearqtr.R r-zoo-1.7-12/R/yearqtr.R --- r-zoo-1.7-11/R/yearqtr.R 2013-07-24 15:08:23.000000000 +0000 +++ r-zoo-1.7-12/R/yearqtr.R 2014-08-29 00:28:52.000000000 +0000 @@ -80,7 +80,7 @@ as.yearqtr(do.call("c", lapply(list(...), as.numeric))) } -cycle.yearqtr <- function(x, ...) as.numeric(quarters(x)) +cycle.yearqtr <- function(x, ...) round(4 * (as.numeric(x) %% 1)) + 1 format.yearqtr <- function(x, format = "%Y Q%q", ...) { @@ -108,12 +108,12 @@ } -months.yearqtr <- function(x, abbreviate) { - months(as.Date(x), abbreviate) +months.yearqtr <- function(x, abbreviate = FALSE) { + months(as.Date(x), abbreviate = abbreviate) } -quarters.yearqtr <- function(x, abbreviate) { - quarters(as.Date(x), abbreviate) +quarters.yearqtr <- function(x, abbreviate = FALSE) { + quarters(as.Date(x), abbreviate = abbreviate) } diff -Nru r-zoo-1.7-11/R/zoo.R r-zoo-1.7-12/R/zoo.R --- r-zoo-1.7-11/R/zoo.R 2013-06-28 07:45:06.000000000 +0000 +++ r-zoo-1.7-12/R/zoo.R 2014-08-29 01:14:31.000000000 +0000 @@ -217,9 +217,11 @@ if(NCOL(object) > 0L & is.null(colnames(object))) stop("only possible for zoo series with column names") wi <- match(x, colnames(object)) if(is.na(wi)) { - object <- cbind(object, value) - if(is.null(dim(object))) dim(object) <- c(length(object), 1) - colnames(object)[NCOL(object)] <- x + if(!is.null(value)) { + object <- cbind(object, value) + if(is.null(dim(object))) dim(object) <- c(length(object), 1) + colnames(object)[NCOL(object)] <- x + } } else { if(is.null(value)) { object <- object[, -wi, drop = FALSE] @@ -351,3 +353,14 @@ ## return zoo zoo(`_data`, ix, freq) } + +`dim<-.zoo` <- function(x, value) { + d <- dim(x) + l <- length(x) + ok <- isTRUE(all.equal(d, value)) || ## no change + (is.null(d) && l == 0L && all(value == c(length(index(x)), 0L))) || ## zero-length vector -> 0-column matrix + (is.null(d) && l > 0L && all(value == c(l, 1L))) || ## positive-length vector -> 1-column matrix + (!is.null(d) && d[2L] <= 1L && is.null(value)) ## 0- or 1-column matrix -> vector + if(!ok) warning("setting this dimension may lead to an invalid zoo object") + NextMethod() +} diff -Nru r-zoo-1.7-11/R/zooreg.R r-zoo-1.7-12/R/zooreg.R --- r-zoo-1.7-11/R/zooreg.R 2012-01-23 20:33:33.000000000 +0000 +++ r-zoo-1.7-12/R/zooreg.R 2015-03-05 22:00:15.000000000 +0000 @@ -9,14 +9,14 @@ ## check data and choose default if (missing(data) || is.null(data)) data <- NA - if(!(is.vector(data) || is.factor(data) || is.matrix(data) || is.data.frame(data))) + if(!(is.vector(data) || is.factor(data) || is.atomic(data) || is.matrix(data) || is.data.frame(data))) stop(paste(dQuote("data"), ": attempt to define invalid zoo object")) if(is.matrix(data) || is.data.frame(data)) data <- as.matrix(data) ## if no index (i.e., order.by) is specified: behave as ts() ## else: behave as zoo() if (is.null(order.by)) { - if(!any(c(is.vector(data), is.factor(data), is.matrix(data), is.data.frame(data)))) + if(!any(c(is.vector(data), is.factor(data), is.atomic(data), is.matrix(data), is.data.frame(data)))) stop(paste(dQuote("data"), ": attempt to define invalid zoo object")) ndata <- NROW(data) diff -Nru r-zoo-1.7-11/src/init.c r-zoo-1.7-12/src/init.c --- r-zoo-1.7-11/src/init.c 2014-02-27 08:32:43.000000000 +0000 +++ r-zoo-1.7-12/src/init.c 2015-03-16 13:27:04.000000000 +0000 @@ -20,7 +20,7 @@ */ -#include "zoo.h" +#include #include static const diff -Nru r-zoo-1.7-11/src/lag.c r-zoo-1.7-12/src/lag.c --- r-zoo-1.7-11/src/lag.c 2014-02-27 08:32:43.000000000 +0000 +++ r-zoo-1.7-12/src/lag.c 2015-03-16 13:27:04.000000000 +0000 @@ -23,7 +23,7 @@ #include #include #include -#include "zoo.h" +#include SEXP zoo_lag (SEXP x, SEXP _k, SEXP _pad) { @@ -50,7 +50,12 @@ PROTECT(result = allocVector(TYPEOF(x), length(x) - (PAD ? 0 : abs(k)*nc))); P++; - int nrr = (int)(length(result)/nc); + + int nrr; + if(length(result) > 0) + nrr = (int)(length(result)/nc); + else /* handle zero-length objects */ + nrr = nr - (PAD ? 0 : abs(k)); if(k_positive) { switch(TYPEOF(x)) { diff -Nru r-zoo-1.7-11/src/Makevars r-zoo-1.7-12/src/Makevars --- r-zoo-1.7-11/src/Makevars 1970-01-01 00:00:00.000000000 +0000 +++ r-zoo-1.7-12/src/Makevars 2015-03-15 20:26:52.000000000 +0000 @@ -0,0 +1 @@ +PKG_CPPFLAGS = -I../inst/include diff -Nru r-zoo-1.7-11/src/Makevars.win r-zoo-1.7-12/src/Makevars.win --- r-zoo-1.7-11/src/Makevars.win 1970-01-01 00:00:00.000000000 +0000 +++ r-zoo-1.7-12/src/Makevars.win 2015-03-15 20:26:52.000000000 +0000 @@ -0,0 +1 @@ +PKG_CPPFLAGS = -I../inst/include diff -Nru r-zoo-1.7-11/src/zoo.h r-zoo-1.7-12/src/zoo.h --- r-zoo-1.7-11/src/zoo.h 2014-02-27 08:32:43.000000000 +0000 +++ r-zoo-1.7-12/src/zoo.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,20 +0,0 @@ -/* -Header file for using internal C-level facilities -provided by zoo. - -This is not 100% designed for end users, so -any user comments and bug reports are very -welcomed. - -Copyright Jeffrey A. Ryan 2010 -*/ - -#include -#include - -#ifndef _Zoo -#define _Zoo - -SEXP zoo_lag (SEXP x, SEXP _k, SEXP _pad); -SEXP zoo_coredata (SEXP x, SEXP copyAttr); -#endif diff -Nru r-zoo-1.7-11/tests/bugfixes.R r-zoo-1.7-12/tests/bugfixes.R --- r-zoo-1.7-11/tests/bugfixes.R 2012-08-03 20:44:17.000000000 +0000 +++ r-zoo-1.7-12/tests/bugfixes.R 2014-08-29 01:25:52.000000000 +0000 @@ -25,3 +25,7 @@ z <- zoo(sin(0:20)) identical(z, rollmedian(z, 1)) identical(coredata(rollmedian(z, 1)), as.vector(runmed(coredata(z), 1))) + +## na.fill with just NAs (directly and implicitly through rollapply) +na.fill(c(NA, NA), fill = NA) +rollapply(1:2, 3, sum, fill = NA) diff -Nru r-zoo-1.7-11/tests/bugfixes.Rout.save r-zoo-1.7-12/tests/bugfixes.Rout.save --- r-zoo-1.7-11/tests/bugfixes.Rout.save 2014-02-20 23:52:20.000000000 +0000 +++ r-zoo-1.7-12/tests/bugfixes.Rout.save 2014-08-29 01:35:46.000000000 +0000 @@ -1,6 +1,6 @@ -R version 3.0.2 (2013-09-25) -- "Frisbee Sailing" -Copyright (C) 2013 The R Foundation for Statistical Computing +R version 3.1.1 (2014-07-10) -- "Sock it to Me" +Copyright (C) 2014 The R Foundation for Statistical Computing Platform: x86_64-pc-linux-gnu (64-bit) R is free software and comes with ABSOLUTELY NO WARRANTY. @@ -64,6 +64,12 @@ > identical(coredata(rollmedian(z, 1)), as.vector(runmed(coredata(z), 1))) [1] TRUE > +> ## na.fill with just NAs (directly and implicitly through rollapply) +> na.fill(c(NA, NA), fill = NA) +[1] NA NA +> rollapply(1:2, 3, sum, fill = NA) +[1] NA NA +> > proc.time() user system elapsed - 1.144 0.040 1.182 + 1.044 0.036 1.072 diff -Nru r-zoo-1.7-11/tests/Examples/zoo-Ex.Rout.save r-zoo-1.7-12/tests/Examples/zoo-Ex.Rout.save --- r-zoo-1.7-11/tests/Examples/zoo-Ex.Rout.save 2014-02-20 23:45:49.000000000 +0000 +++ r-zoo-1.7-12/tests/Examples/zoo-Ex.Rout.save 2015-03-16 13:26:17.000000000 +0000 @@ -1,6 +1,6 @@ -R version 3.0.2 (2013-09-25) -- "Frisbee Sailing" -Copyright (C) 2013 The R Foundation for Statistical Computing +R version 3.1.2 (2014-10-31) -- "Pumpkin Helmet" +Copyright (C) 2014 The R Foundation for Statistical Computing Platform: x86_64-pc-linux-gnu (64-bit) R is free software and comes with ABSOLUTELY NO WARRANTY. @@ -946,13 +946,11 @@ > ### ** Examples > > -> z <- zooreg(rep(10 * seq(4), each = 4) + rep(c(3, 1, 2, 4), times = 4), +> z <- zooreg(rep(10 * seq(8), each = 4) + rep(c(3, 1, 2, 4), times = 8), + start = as.yearqtr(2000), freq = 4) -> z[10] <- NA +> z[25] <- NA > > zout <- na.StructTS(z) -[1] "entering zoo method" -[1] "entering ts method" > > plot(cbind(z, zout), screen = 1, col = 1:2, type = c("l", "p"), pch = 20) > @@ -1526,6 +1524,29 @@ + srt = -90, xpd = TRUE, col = "blue") > par(opar) > +> +> ## another plot with left and right axes +> ## modified from https://stat.ethz.ch/pipermail/r-help/2014-May/375293.html +> d1 <- c(38.2, 18.1, 83.2, 42.7, 22.8, 48.1, 81.8, 129.6, 52.0, 110.3) +> d2 <- c(2.2, 0.8, 0.7, 1.6, 0.9, 0.9, 1.1, 2.8, 5.1, 2.1) +> z1 <- zooreg(d1, start = as.POSIXct("2013-01-01 00:00:01"), frequency = 0.0000006) +> z2 <- zooreg(d2, start = as.POSIXct("2013-01-01 00:00:20"), frequency = 0.0000006) +> zt <- zooreg(rnorm(1050), start = as.POSIXct("2013-01-01 00:00:01"), frequency = 0.00007) +> z <- merge(zt, z1, z2, all = TRUE) +> z <- na.spline(z[,2:3], na.rm = FALSE) +> ## function to round up to a number divisible by n (2011 by Owen Jones) +> roundup <- function(x, n) ceiling(ceiling(x)/n) * n +> ## plot how to match secondary y-axis ticks to primary ones +> plot(z$z1, ylim = c(0, signif(max(na.omit(z$z1)), 2)), xlab = "") +> ## use multiplication for even tick numbers and fake sekondary y-axis +> max.yl <- roundup(max(na.omit(z$z2)), par("yaxp")[3]) +> multipl.yl <- max(na.omit(z$z2)) / max.yl +> multipl.z2 <- signif(max(na.omit(z$z1) * 1.05), 2)/max.yl +> lines(z$z2 * multipl.z2, lty = 2) +> at4 <- axTicks(4) +> axis(4, at = at4, seq(0, max.yl, length.out = par("yaxp")[3] + 1)) +> +> > # automatically placed point labels > ## Not run: > ##D library("maptools") @@ -1594,6 +1615,14 @@ > ##D tkexamp(plot(z), tke.test1, plotloc = "top") > ## End(Not run) > +> # setting ylim on a multi-panel plot - 2nd panel y axis range is 1-50 +> data("anscombe", package = "datasets") +> ans6 <- zoo(anscombe[, 1:6]) +> screens <- c(1, 1, 2, 2, 3, 3) +> ylim <- unname(tapply(as.list(ans6), screens, range)) +> ylim[[2]] <- 1:50 # or ylim[[2]] <- c(1, 50) +> plot(ans6, screens = screens, ylim = ylim) +> > > > @@ -1611,8 +1640,56 @@ > > ### ** Examples > +> ## this manual page provides a few typical examples, many more cases +> ## are covered in vignette("zoo-read", package = "zoo") +> +> ## read text lines with a single date column +> Lines <- "2013-12-24 2 ++ 2013-12-25 3 ++ 2013-12-26 8" +> read.zoo(text = Lines, FUN = as.Date) # explicit coercion +2013-12-24 2013-12-25 2013-12-26 + 2 3 8 +> read.zoo(text = Lines, format = "%Y-%m-%d") # same +2013-12-24 2013-12-25 2013-12-26 + 2 3 8 +> read.zoo(text = Lines) # same, via heuristic +2013-12-24 2013-12-25 2013-12-26 + 2 3 8 +> +> ## read text lines with date/time in separate columns +> Lines <- "2013-11-24 12:41:21 2 ++ 2013-12-25 12:41:22.25 3 ++ 2013-12-26 12:41:22.75 8" +> read.zoo(text = Lines, index = 1:2, ++ FUN = paste, FUN2 = as.POSIXct) # explicit coercion +2013-11-24 12:41:21 2013-12-25 12:41:22 2013-12-26 12:41:22 + 2 3 8 +> read.zoo(text = Lines, index = 1:2, tz = "") # same +2013-11-24 12:41:21 2013-12-25 12:41:22 2013-12-26 12:41:22 + 2 3 8 +> read.zoo(text = Lines, index = 1:2) # same, via heuristic +2013-11-24 12:41:21 2013-12-25 12:41:22 2013-12-26 12:41:22 + 2 3 8 +> +> ## read directly from a data.frame (artificial and built-in BOD) +> dat <- data.frame(date = paste("2000-01-", 10:15, sep = ""), ++ a = sin(1:6), b = cos(1:6)) +> read.zoo(dat) + a b +2000-01-10 0.8414710 0.5403023 +2000-01-11 0.9092974 -0.4161468 +2000-01-12 0.1411200 -0.9899925 +2000-01-13 -0.7568025 -0.6536436 +2000-01-14 -0.9589243 0.2836622 +2000-01-15 -0.2794155 0.9601703 +> data("BOD", package = "datasets") +> read.zoo(BOD) + 1 2 3 4 5 7 + 8.3 10.3 19.0 16.0 15.6 19.8 +> > ## Not run: -> ##D ## See also vignette("zoo-read", package = "zoo") for more examples +> ##D ## descriptions of typical examples > ##D > ##D ## turn *numeric* first column into yearmon index > ##D ## where number is year + fraction of year represented by month @@ -1650,6 +1727,9 @@ > ##D ## and no headers. T appears literally. Requires chron 2.3-22 or later. > ##D z <- read.zoo("foo.csv", FUN = as.chron) > ##D +> ##D # read in all csv files in the current directory and merge them +> ##D read.zoo(Sys.glob("*.csv"), header = TRUE, sep = ",") +> ##D > ##D # We use "NULL" in colClasses for those columns we don't need but in > ##D # col.names we still have to include dummy names for them. Of what > ##D # is left the index is the first three columns (1:3) which we convert @@ -1674,25 +1754,11 @@ > ##D FUN = function(h, m, s) times(paste(h, m, s, sep = ":")), > ##D FUN2 = function(tt) trunc(tt, "00:00:05"), > ##D aggregate = mean) -> ##D -> ##D ## omit the read.table() phase and directly supply a data.frame -> ##D dat <- data.frame(date = paste("2000-01-", 10:15, sep = ""), a = rnorm(6), b = 1:6) -> ##D z <- read.zoo(dat) -> ##D -> ##D ## using built-in data frame BOD -> ##D read.zoo(BOD) -> ##D -> ##D read.zoo(BOD, FUN = as.Date) -> ##D -> ##D read.zoo(BOD[c(1:6, 1), ], aggregate = mean) -> ##D -> ##D # read in all csv files in the current directory and merge them -> ##D read.zoo(Sys.glob("*.csv"), header = TRUE, sep = ",") -> ##D > ## End(Not run) > > > +> > cleanEx() > nameEx("rollapply") > ### * rollapply @@ -1733,6 +1799,7 @@ 2 3 4 5 -0.4261464 0.3144318 0.3630533 0.3681067 > +> > ## rolling regression: > ## set up multivariate zoo series with > ## number of UK driver deaths and lags 1 and 12 @@ -1752,6 +1819,25 @@ > ## and after the seatbelt legislation change in Jan 1983 > plot(rr) > +> +> ## rolling mean by time window (e.g., 3 days) rather than +> ## by number of observations (e.g., when these are unequally spaced): +> # +> ## - test data +> tt <- as.Date("2000-01-01") + c(1, 2, 5, 6, 7, 8, 10) +> z <- zoo(seq_along(tt), tt) +> ## - fill it out to a daily series, zm, using NAs +> ## using a zero width zoo series g on a grid +> g <- zoo(, seq(start(z), end(z), "day")) +> zm <- merge(z, g) +> ## - 3-day rolling mean +> rollapply(zm, 3, mean, na.rm = TRUE, fill = NA) +2000-01-02 2000-01-03 2000-01-04 2000-01-05 2000-01-06 2000-01-07 2000-01-08 + NA 1.5 2.0 3.0 3.5 4.0 5.0 +2000-01-09 2000-01-10 2000-01-11 + 5.5 6.5 NA +> +> > ## different values of rule argument > z <- zoo(c(NA, NA, 2, 3, 4, 5, NA)) > rollapply(z, 3, sum, na.rm = TRUE) @@ -2047,8 +2133,10 @@ 2004-03-14 -0.6212406 > rollsum(x, 3) -[1] 0.4052854 1.8015351 1.0087177 1.7821741 1.5962360 -0.3130755 -2.4460972 -[8] -1.7110095 +2004-01-11 2004-01-15 2004-01-23 2004-02-05 2004-02-21 2004-02-25 2004-03-13 + 0.4052854 1.8015351 1.0087177 1.7821741 1.5962360 -0.3130755 -2.4460972 +2004-03-14 +-1.7110095 > > xm <- zoo(matrix(1:12, 4, 3), x.Date[1:4]) > rollmean(xm, 3) @@ -2064,9 +2152,9 @@ 2004-01-11 2 6 10 2004-01-15 3 7 11 > rollsum(xm, 3) - x.1 x.2 x.3 -[1,] 6 18 30 -[2,] 9 21 33 + +2004-01-11 6 18 30 +2004-01-15 9 21 33 > > rollapply(xm, 3, mean) # uses rollmean @@ -2633,8 +2721,8 @@ > ### mean.zoo median.zoo na.contiguous na.contiguous.data.frame > ### na.contiguous.list na.contiguous.default na.contiguous.zoo scale.zoo > ### xtfrm.zoo names.zoo names<-.zoo quantile.zoo rev.zoo transform.zoo -> ### index2char index2char.default index2char.numeric head.ts tail.ts -> ### ifelse.zoo +> ### ifelse.zoo dim<-.zoo index2char index2char.default index2char.numeric +> ### head.ts tail.ts > ### Keywords: ts > > ### ** Examples @@ -2950,7 +3038,7 @@ > ### > options(digits = 7L) > base::cat("Time elapsed: ", proc.time() - base::get("ptime", pos = 'CheckExEnv'),"\n") -Time elapsed: 6.628 0.104 6.771 0 0 +Time elapsed: 5.4 0.12 5.542 0 0 > grDevices::dev.off() null device 1 diff -Nru r-zoo-1.7-11/vignettes/zoo.bib r-zoo-1.7-12/vignettes/zoo.bib --- r-zoo-1.7-11/vignettes/zoo.bib 2012-04-28 20:14:26.000000000 +0000 +++ r-zoo-1.7-12/vignettes/zoo.bib 2014-08-29 00:28:52.000000000 +0000 @@ -32,7 +32,7 @@ url = {http://www.jstatsoft.org/v07/i02/} } -@Article{AER:Zeileis:2005, +@Article{zoo:Zeileis:2005, author = {Achim Zeileis}, title = {Implementing a Class of Structural Change Tests: An Econometric Computing Approach}, journal = {Computational Statistics \& Data Analysis}, diff -Nru r-zoo-1.7-11/vignettes/zoo-quickref.Rnw r-zoo-1.7-12/vignettes/zoo-quickref.Rnw --- r-zoo-1.7-11/vignettes/zoo-quickref.Rnw 2012-04-28 20:14:26.000000000 +0000 +++ r-zoo-1.7-12/vignettes/zoo-quickref.Rnw 2015-01-24 08:35:49.000000000 +0000 @@ -70,10 +70,14 @@ \end{verbatim} can be read in via <>= +Sys.setlocale("LC_TIME", "C") inrusd <- read.zoo("demo1.txt", sep = "|", format="%d %b %Y") @ The \code{format} argument causes the first column to be transformed -to an index of class \code{"Date"}. +to an index of class \code{"Date"}. The \code{Sys.setlocale} is set to +\code{"C"} here to assure that the English month abbreviations are read +correctly. (It is unnecessary if the system is already set to a locale +that understands English month abbreviations.) The data in \code{demo2.txt} look like \begin{verbatim} diff -Nru r-zoo-1.7-11/vignettes/zoo-read.Rnw r-zoo-1.7-12/vignettes/zoo-read.Rnw --- r-zoo-1.7-11/vignettes/zoo-read.Rnw 2014-01-05 19:11:26.000000000 +0000 +++ r-zoo-1.7-12/vignettes/zoo-read.Rnw 2014-08-29 00:28:52.000000000 +0000 @@ -575,7 +575,7 @@ \newpage -\section{Further comments} +\section*{Further comments} Multiple files can be read and subsequently merged. diff -Nru r-zoo-1.7-11/vignettes/zoo.Rnw r-zoo-1.7-12/vignettes/zoo.Rnw --- r-zoo-1.7-11/vignettes/zoo.Rnw 2012-04-28 20:14:26.000000000 +0000 +++ r-zoo-1.7-12/vignettes/zoo.Rnw 2014-12-06 00:53:17.000000000 +0000 @@ -191,7 +191,7 @@ vectors of classes \code{"Date"}, \code{"POSIXct"} or \code{"times"} from package \pkg{chron} and \code{"timeDate"} in \pkg{timeDate}. Because not all required methods used to be available for \code{"timeDate"} in older -versions of \pkg{fCalendar}, Section~\ref{sec:fCalendar} has a rather outdated example how +versions of \pkg{fCalendar}, Section~\ref{sec:timeDate} has a rather outdated example how to provide such methods so that \code{"zoo"} objects work with \code{"timeDate"} indexes. To achieve this independence of the index class, new generic functions for ordering (\code{ORDER()}) and value matching (\code{MATCH()}) are introduced @@ -220,7 +220,8 @@ @ and one with a sine wave <>= -z2.index <- as.POSIXct(paste(2004, rep(1:2, 5), sample(1:28, 10), sep = "-")) +z2.index <- as.POSIXct(paste(2004, rep(1:2, 5), sample(1:28, 10), + sep = "-")) z2.data <- sin(2*1:10/pi) z2 <- zoo(z2.data, z2.index) @ @@ -436,7 +437,8 @@ <> @ <>= -plot(Z, type = "b", lty = 1:3, pch = list(Aa = 1:5, Bb = 2, Cc = 4), col = list(Bb = 2, 4)) +plot(Z, type = "b", lty = 1:3, pch = list(Aa = 1:5, Bb = 2, Cc = 4), + col = list(Bb = 2, 4)) @ \caption{\label{fig:plot13} Examples of multiple panel plots} \end{center} @@ -540,10 +542,12 @@ quarterly series, convert it to a \code{"zoo} class series, insert intermediate quarterly points containing \code{NA} values and then fill the \code{NA} values using \code{na.approx}, \code{na.locf} -or \code{na.spline}: +or \code{na.spline}. (More details on \code{NA} handling in general can be found +in Section~\ref{sec:NA}.) <>= -Nile.na <- merge(as.zoo(Nile), zoo(, seq(start(Nile)[1], end(Nile)[1], 1/4))) +Nile.na <- merge(as.zoo(Nile), + zoo(, seq(start(Nile)[1], end(Nile)[1], 1/4))) head(as.zoo(Nile)) head(na.approx(Nile.na)) head(na.locf(Nile.na)) @@ -684,16 +688,16 @@ \subsection[NA handling]{\code{NA} handling} \label{sec:NA} -Four methods for dealing with \code{NA}s (missing observations) -in the observations are applicable to \code{"zoo"} objects: -\code{na.omit}, \code{na.contiguous}, \code{na.approx} and \code{na.locf}. +A wide range of methods for dealing with \code{NA}s (missing observations) +in the observations are applicable to \code{"zoo"} objects including +\code{na.omit}, \code{na.contiguous}, \code{na.approx}, \code{na.spline}, and \code{na.locf} among others. \code{na.omit}---or its default method to be more precise---returns a \code{"zoo"} object with incomplete observations removed. \code{na.contiguous} extracts the longest consecutive stretch of non-missing values. Furthermore, new generic functions -\code{na.approx} and \code{na.locf} and corresponding default methods are introduced in \pkg{zoo}. -The former replaces \code{NA}s by linear interpolation (using the -function \code{approx}) and the name of the latter +\code{na.approx}, \code{na.spline}, and \code{na.locf} and corresponding default methods are introduced in \pkg{zoo}. +The former two replace \code{NA}s by interpolation (using the +function \code{approx} and \code{spline}, respectively) and the name of the latter stands for \underline{l}ast \underline{o}bservation \underline{c}arried \underline{f}orward. It replaces missing observations by the most recent non-\code{NA} prior to it. Leading \code{NA}s, which cannot be replaced @@ -706,13 +710,18 @@ na.contiguous(z1) na.approx(z1) na.approx(z1, 1:NROW(z1)) +na.spline(z1) na.locf(z1) @ -As the above example illustrates, \code{na.approx} uses by default +As the above example illustrates, \code{na.approx} (and also \code{na.spline}) use by default the underlying time scale for interpolation. This can be changed, e.g., to an equidistant spacing, by setting the second argument of -\code{na.approx}. +\code{na.approx}. Furthermore, a different output time index can be supplied as well. + +In addition to the methods discussed above, there are also other methods +for dealing with missing values in \pkg{zoo} such as \code{na.aggregate}, +\code{na.fill}, \code{na.trim}, and \code{na.StructTS}. \subsection{Rolling functions} \label{sec:rolling}