Skip to content
Browse files

fix PR#15068 and more

git-svn-id: https://svn.r-project.org/R/trunk@60904 00db46b3-68df-0310-9c12-caf00c1e9a41
  • Loading branch information...
1 parent 95db153 commit eda9c0e48efb7e78d885e2915073a93fa99e95b8 ripley committed Oct 8, 2012
Showing with 20 additions and 5 deletions.
  1. +3 −0 doc/NEWS.Rd
  2. +3 −2 src/library/stats/R/ts.R
  3. +4 −3 src/library/stats/man/arima.sim.Rd
  4. +10 −0 tests/reg-tests-1b.R
View
3 doc/NEWS.Rd
@@ -980,6 +980,9 @@
\item The code for creating \code{coerce()} methods could
generate false notes about ambiguous selection; the notes have
been suppressed for this function.
+
+ \item \code{arima.sim()} could give too long an output in some
+ corner cases (in part, \PR{15068}).
}
}
}
View
5 src/library/stats/R/ts.R
@@ -765,6 +765,7 @@ arima.sim <- function(model, n, rand.gen = rnorm,
start.innov = rand.gen(n.start, ...), ...)
{
if(!is.list(model)) stop("'model' must be list")
+ if(n <= 0L) stop("'n' must be strictly positive")
p <- length(model$ar)
if(p) {
minroots <- min(Mod(polyroot(c(1, -model$ar))))
@@ -788,13 +789,13 @@ arima.sim <- function(model, n, rand.gen = rnorm,
"'start.innov' is too short: need %d point",
"'start.innov' is too short: need %d points"),
n.start), domain = NA)
- x <- ts(c(start.innov[1L:n.start], innov[1L:n]), start = 1 - n.start)
+ x <- ts(c(start.innov[seq_len(n.start)], innov[1L:n]), start = 1 - n.start)
if(length(model$ma)) {
x <- filter(x, c(1, model$ma), sides = 1L)
x[seq_along(model$ma)] <- 0 # rather than NA
}
if(length(model$ar)) x <- filter(x, model$ar, method = "recursive")
- if(n.start > 0) x <- x[-(1L:n.start)]
+ if(n.start > 0) x <- x[-(seq_len(n.start))]
if(d > 0) x <- diffinv(x, differences = d)
as.ts(x)
}
View
7 src/library/stats/man/arima.sim.Rd
@@ -1,6 +1,6 @@
% File src/library/stats/man/arima.sim.Rd
% Part of the R package, http://www.R-project.org
-% Copyright 1995-2007 R Core Team
+% Copyright 1995-2012 R Core Team
% Distributed under GPL 2 or later
\name{arima.sim}
@@ -18,9 +18,10 @@ arima.sim(model, n, rand.gen = rnorm, innov = rand.gen(n, \dots),
\arguments{
\item{model}{A list with component \code{ar} and/or \code{ma} giving
the AR and MA coefficients respectively. Optionally a component
- \code{order} can be used. An empty list gives an ARIMA(0, 0, 0)
+ \code{order} can be used. An empty list gives an ARIMA(0, 0, 0)
model, that is white noise.}
- \item{n}{length of output series, before un-differencing.}
+ \item{n}{length of output series, before un-differencing. A stricly
+ positive integer.}
\item{rand.gen}{optional: a function to generate the innovations.}
\item{innov}{an optional times series of innovations. If not
provided, \code{rand.gen} is used.}
View
10 tests/reg-tests-1b.R
@@ -1979,8 +1979,18 @@ if(is.na(z[2]) || is.na(z10[2])) {
} else stopifnot(z[2] > z10[2])
## Previous test ould be defeated by compiler optimization.
+
+##
options(max.print=.Machine$integer.max)
1 ## segfaulted because of integer overflow
stopifnot(identical(.Machine$integer.max, getOption("max.print")))
+##
+
+## corner cases for arima.sim(), in part PR#15068
+stopifnot(length(arima.sim(list(order = c(0,0,0)), n = 10)) == 10)
+stopifnot(inherits(try(arima.sim(list(order = c(1,0,0), ar = 0.7), n = 0)),
+ "try-error"))
+## one too long in R < 2.15.2
+
proc.time()

0 comments on commit eda9c0e

Please sign in to comment.
Something went wrong with that request. Please try again.