| Line 306... |
Line 306... |
| 306 |
setMethod("toeplitz", "A", function(x, ...) x)
|
306 |
setMethod("toeplitz", "A", function(x, ...) x)
|
| 307 |
(mm <- selectMethod(toeplitz, "numeric"))
|
307 |
(mm <- selectMethod(toeplitz, "numeric"))
|
| 308 |
stopifnot(identical(T3, print(toeplitz(x, r))), removeGeneric("toeplitz"))
|
308 |
stopifnot(identical(T3, print(toeplitz(x, r))), removeGeneric("toeplitz"))
|
| 309 |
## badly failed since r82364 when stats::toeplitz was generalized to 3 args
|
309 |
## badly failed since r82364 when stats::toeplitz was generalized to 3 args
|
| 310 |
|
310 |
|
| - |
|
311 |
## trace() a function whose S3 class() has multiple strings,
|
| - |
|
312 |
## e.g. S7 generics and methods
|
| - |
|
313 |
setOldClass(c("myfun", "function"))
|
| - |
|
314 |
f <- structure(function(x) x, class = c("myfun", "function"))
|
| - |
|
315 |
n <- 0
|
| - |
|
316 |
suppressMessages( # error: 'length = 2' in coercion to 'logical(1)' in R <= 4.5.x
|
| - |
|
317 |
trace("f", quote(n <<- n + 1), print = FALSE))
|
| - |
|
318 |
f1 <- f(1)
|
| - |
|
319 |
untrace("f")
|
| - |
|
320 |
stopifnot(identical(f1, 1), identical(n, 1),
|
| - |
|
321 |
identical(class(f), c("myfun", "function")),
|
| - |
|
322 |
identical(f(2), 2), identical(n, 1)) # f no longer traced
|
| - |
|
323 |
|
| - |
|
324 |
setClass("myS4Fun", contains = "function", slots = c(label = "character"))
|
| - |
|
325 |
g <- new("myS4Fun", function(x) x, label = "kept")
|
| - |
|
326 |
n <- 0
|
| - |
|
327 |
suppressMessages(
|
| - |
|
328 |
trace("g", quote(n <<- n + 1), print = FALSE))
|
| - |
|
329 |
g1 <- g(1)
|
| - |
|
330 |
stopifnot(identical(g@label, "kept"))
|
| - |
|
331 |
untrace("g")
|
| - |
|
332 |
stopifnot(identical(g1, 1), identical(n, 1),
|
| - |
|
333 |
is(g, "myS4Fun"), identical(g@label, "kept"),
|
| - |
|
334 |
identical(g(2), 2), identical(n, 1)) # g no longer traced
|
| - |
|
335 |
|
| - |
|
336 |
setClass("myS3FunS4", contains = c("function", "VIRTUAL"),
|
| - |
|
337 |
slots = c(label = "character"))
|
| - |
|
338 |
setOldClass(c("myS3Fun", "function"), S4Class = "myS3FunS4")
|
| - |
|
339 |
h <- structure(function(x) x, class = c("myS3Fun", "function"),
|
| - |
|
340 |
label = "kept")
|
| - |
|
341 |
n <- 0
|
| - |
|
342 |
suppressMessages(
|
| - |
|
343 |
trace("h", quote(n <<- n + 1), print = FALSE))
|
| - |
|
344 |
h1 <- h(1)
|
| - |
|
345 |
stopifnot(identical(h@label, "kept"))
|
| - |
|
346 |
untrace("h")
|
| - |
|
347 |
stopifnot(identical(h1, 1), identical(n, 1),
|
| - |
|
348 |
identical(class(h), c("myS3Fun", "function")),
|
| - |
|
349 |
identical(attr(h, "label"), "kept"),
|
| - |
|
350 |
identical(h(2), 2), identical(n, 1)) # h no longer traced
|
| - |
|
351 |
|
| 311 |
cat('Time elapsed: ', proc.time(),'\n')
|
352 |
cat('Time elapsed: ', proc.time(),'\n')
|