Skip to content

Commit 5a264c1

Browse files
author
maechler
committed
update implicitGeneric toeplitz(): default has 3 args now
git-svn-id: https://svn.r-project.org/R/trunk@89146 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent 1b9d6e3 commit 5a264c1

File tree

4 files changed

+20
-6
lines changed

4 files changed

+20
-6
lines changed

doc/NEWS.Rd

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,10 @@
448448
\item Subassignment, \code{x[ind] <- val}, to 1-dimensional
449449
\code{array}s no longer \dQuote{drops} them to simple vectors when
450450
\code{ind} is a name, fixing \PR{18973}, reported by \I{Thomas Soeiro}.
451+
452+
\item The implicitGeneric definition for \code{toeplitz()} produced a
453+
default method that failed when \code{toeplitz(x, r)} was called with
454+
more than the first argument. Simple fix from \I{Mikael Jagan}.
451455
}
452456
}
453457
}

src/library/methods/R/makeBasicFunsList.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# File src/library/methods/R/makeBasicFunsList.R
22
# Part of the R package, https://www.R-project.org
33
#
4-
# Copyright (C) 1995-2024 The R Core Team
4+
# Copyright (C) 1995-2025 The R Core Team
55
#
66
# This program is free software; you can redistribute it and/or modify
77
# it under the terms of the GNU General Public License as published by
@@ -279,7 +279,7 @@ utils::globalVariables(".addBasicGeneric")
279279

280280
## our toeplitz() only has 'x'; want the generic "here" rather than "out there"
281281
setGeneric("toeplitz", function(x, ...) standardGeneric("toeplitz"),
282-
useAsDefault= function(x, ...) stats::toeplitz(x),
282+
useAsDefault = function(x, ...) stats::toeplitz(x, ...),
283283
signature = "x", where = where)
284284
setGenericImplicit("toeplitz", where, FALSE)
285285

src/library/stats/R/diffinv.R

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,15 @@ diffinv.vector <- function (x, lag = 1L, differences = 1L, xi, ...)
2626
if (!is.vector(x)) stop ("'x' is not a vector")
2727
lag <- as.integer(lag); differences <- as.integer(differences)
2828
if (lag < 1L || differences < 1L) stop ("bad value for 'lag' or 'differences'")
29-
if(missing(xi)) xi <- rep(0., lag*differences)
30-
if (length(xi) != lag*differences)
29+
if(missing(xi))
30+
xi <- rep(0., lag*differences)
31+
else if (length(xi) != lag*differences)
3132
stop("'xi' does not have the right length")
3233
if (differences == 1L) {
3334
x <- as.double(x)
3435
xi <- as.double(xi)
3536
n <- as.integer(length(x))
3637
if(is.na(n)) stop(gettextf("invalid value of %s", "length(x)"), domain = NA)
37-
# y <- c(xi[1L:lag], double(n))
38-
# z <- .C(C_R_intgrt_vec, x, y = y, as.integer(lag), n)$y
3938
.Call(C_intgrt_vec, x, xi, lag)
4039
}
4140
else

tests/classes-methods.R

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,5 +219,16 @@ B <- as(new("A"), "B") ## gave Error in asMethod@generic : ... `@` applied to
219219
stopifnot(identical(B, new("B")))
220220

221221

222+
## toeplitz() implicit generic
223+
x <- c(-1, 0,0)
224+
r <- c(-1,11,0)
225+
(T3 <- toeplitz(x, r))
226+
## dummy method triggering (implicit) creation of S4 generic and default
227+
setMethod("toeplitz", "A", function(x, ...) x)
228+
(mm <- selectMethod(toeplitz, "numeric"))
229+
stopifnot(identical(T3, print(toeplitz(x, r))), removeGeneric("toeplitz"))
230+
## badly failed since r82364 when stats::toeplitz was generalized to 3 args
231+
232+
222233

223234
cat('Time elapsed: ', proc.time(),'\n')

0 commit comments

Comments
 (0)