Skip to content

Commit 9ad8999

Browse files
author
maechler
committed
fix PR#18824 -- debugonce(<simple_body>) and "typo" in r87345`s patch
git-svn-id: https://svn.r-project.org/R/trunk@87347 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent f47f867 commit 9ad8999

File tree

3 files changed

+51
-6
lines changed

3 files changed

+51
-6
lines changed

doc/NEWS.Rd

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,11 +360,15 @@
360360
\PR{18782}.
361361

362362
\item \code{axisTicks(usr, ...)} documentation clarification for
363-
\code{log=TRUE}, fixing bug \PR{18821} thanks to Duncan Murdoch.
363+
\code{log=TRUE}, fixing bug \PR{18821} thanks to \I{Duncan Murdoch}.
364364

365365
\item \code{debug()} and \code{debugonce(fun)} now also accept a
366366
string \code{fun} when it names an S4 generic, fixing \PR{18822}
367-
thanks to Michael Jagan.
367+
thanks to \I{Michael Jagan}.
368+
369+
\item \code{debugonce(<S4-simple-body>, signature=*)} now works
370+
correctly when \dQuote{called twice}, fixing \PR{18824} thanks to
371+
\I{Michael Jagan}.
368372
}
369373
}
370374
}

src/library/methods/R/debug.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@
22
once = FALSE)
33
{
44
stopifnot(is.null(condition), identical(text, ""))
5-
fun <- getGeneric(fun, mustWork = TRUE)
5+
fun <- getGeneric(fun, mustFind = TRUE)
66

77
if(isdebugged(fun, signature = signature))
88
return(invisible(NULL))
9-
10-
m <- selectMethod(fun, signature)
9+
10+
m <- .untracedFunction(selectMethod(fun, signature))
1111
bd <- body(m)
1212

1313
isrematch <- isRematched(m)
1414
if(isrematch)
1515
bd <- body(bd[[2L]][[3L]])
1616

1717
at <- if(is(bd, "{")) 2L else numeric()
18-
18+
1919
tracer <- if(once) {
2020
## If the method is rematched we're in .local so we need to reach up one
2121
## frame to get the generic and target in that case

tests/reg-tests-1e.R

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1552,13 +1552,54 @@ for(x in list(x3 = {n <- 3L; x <- diag(n); x[n,n] <- 0; x},
15521552
}
15531553
## kappa(..) returned 1 or {0 with a warning} in R <= 4.4.2
15541554

1555+
15551556
## hexadecimal contants with and without exponent.
15561557
0x1.234p0
15571558
0x1.234p7
15581559
0x1.234p-7
15591560
0x1.234
15601561
## last was a (deliberate) parse error in R <= 4.4.2, but not as documented.
15611562

1563+
1564+
## PR#18822 -- debug("<S4-generic>")
1565+
m0 <- selectMethod("Ops", signature = (SIG <- c("array", "array")))
1566+
stopifnot(is.function(m0), inherits(m0, "PossibleMethod"))
1567+
debug ("Ops", signature = SIG) # gave Error
1568+
(m1 <- selectMethod("Ops", SIG))
1569+
untrace("Ops", signature=SIG) ; m2 <- selectMethod("Ops", SIG)
1570+
debugonce("Ops", signature = SIG) # Error ..
1571+
m3 <- selectMethod("Ops", SIG)
1572+
untrace("Ops", signature=SIG) ; m4 <- selectMethod("Ops", SIG)
1573+
stopifnot(exprs = {
1574+
is(m0, "MethodDefinition")
1575+
identical(m0, m2)
1576+
identical(m0, m4)
1577+
is(m1, "MethodDefinitionWithTrace")
1578+
is(m3, "MethodDefinitionWithTrace") # but not the same
1579+
})
1580+
## both debug(..) and debugonce(..) failed
1581+
1582+
1583+
## debugonce(<simple>) error when called twice -- PR#18824
1584+
setGeneric("zzz", function(x) standardGeneric("zzz"))
1585+
setMethod("zzz", c(x = "NULL"), function(x) NULL)
1586+
m0 <- selectMethod(zzz, signature = "NULL")
1587+
debugonce(zzz, signature = "NULL")
1588+
m1 <- selectMethod(zzz, signature = "NULL")
1589+
debugonce(zzz, signature = "NULL") # gave error "cannot use 'at' argument unless ..."
1590+
m2 <- selectMethod(zzz, signature = "NULL")
1591+
untrace(zzz, signature = "NULL")
1592+
m3 <- selectMethod(zzz, signature = "NULL")
1593+
stopifnot(exprs = {
1594+
is(m0, "MethodDefinition")
1595+
is(m1, "MethodDefinitionWithTrace")
1596+
identical(m0, m3)
1597+
identical(m1, m2)
1598+
})
1599+
## 2nd debugonce() call failed in R <= 4.4.2
1600+
1601+
1602+
15621603
## keep at end
15631604
rbind(last = proc.time() - .pt,
15641605
total = proc.time())

0 commit comments

Comments
 (0)