Skip to content

Commit a212f32

Browse files
author
maechler
committed
diff.ts(<1x1 matrix>) now is matrix
git-svn-id: https://svn.r-project.org/R/trunk@89093 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent 02c6045 commit a212f32

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

doc/NEWS.Rd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@
403403
\item \code{diff(m, lag, dif)} for matrix \code{m} now still returns
404404
matrices, also when \code{lag * dif > nrow(m)} (\PR{18972}, thanks to
405405
\I{Mikael Jagan}).
406+
\code{diff(<ts-matrix>)} remains matrix, even when it has length zero.
406407
407408
\item \code{str(x, give.attr=FALSE)} no longer shows attributes when
408409
\code{x} is a zero length \code{"Date"} or \code{"POSIXt"} object.

src/library/stats/R/ts.R

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,11 @@ Ops.ts <- function(e1, e2)
243243
c(deparse(substitute(e1))[1L],
244244
deparse(substitute(e2))[1L]),
245245
union = FALSE)
246+
if(is.null(e12))# if e1 or e2 is matrix but e1 & e2 are not overlapping, e12 is NULL ..
247+
return(if(is.matrix(e1)) e1[0, , drop=FALSE]
248+
else if(is.matrix(e2)) e2[0, , drop=FALSE]
249+
## else NULL ( == e12 )
250+
)
246251
e1 <- if(is.matrix(e1)) e12[, 1L:nc1 , drop = FALSE] else e12[, 1]
247252
e2 <- if(is.matrix(e2)) e12[, nc1 + (1L:nc2), drop = FALSE] else e12[, nc1 + 1]
248253
NextMethod(.Generic)

tests/reg-tests-1e.R

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2386,6 +2386,11 @@ str(L, give.attr=FALSE) # now 0 x 1 matrices
23862386
stopifnot( print(
23872387
vapply(L, \(.) identical(.$f0 - .$f0, .$f), NA) ) )
23882388
## were all FALSE : diff(fnm, 2,5) was not a matrix
2389+
m <- ts(matrix(1)) # ts-matrix boundary case
2390+
d1 <- m - lag(m, -1) # warning: non-intersecting series
2391+
d2 <- diff(m)
2392+
stopifnot(identical(d1,d2), identical(dim(d1), 0:1))
2393+
## both d1 & d2 were *not* matrix in R <= 4.5.2
23892394

23902395

23912396
## str.{Date,POSIXt}(<length 0>, give.attr=FALSE) - now works

0 commit comments

Comments
 (0)