Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e3e0882

Browse files
author
maechler
committedMar 14, 2025·
fixing trace(coerce, ..) etc
git-svn-id: https://svn.r-project.org/R/trunk@87971 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent 35c1f37 commit e3e0882

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed
 

‎doc/NEWS.Rd

+3
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,9 @@
751751
as \code{NA}.
752752
753753
\item \code{vignette("reshape")} is now also available on Windows.
754+
755+
\item \code{trace(coerce, ..)} now works correctly, fixing \PR{18823}
756+
thanks to \I{Mikael Jagan}.
754757
}
755758
}
756759
}

‎src/library/methods/R/as.R

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# File src/library/methods/R/as.R
22
# Part of the R package, https://www.R-project.org
33
#
4-
# Copyright (C) 1995-2019 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
@@ -91,6 +91,9 @@ as <-
9191
}
9292
}
9393
}
94+
environment(asMethod) <- asMethodEnv <- new.env(parent = environment(asMethod))
95+
loadMethod(asMethod, envir = asMethodEnv)
96+
assign(".Generic", asMethod@generic, envir = asMethodEnv)
9497
if(strict)
9598
asMethod(object)
9699
else

‎tests/classes-methods.R

+16
Original file line numberDiff line numberDiff line change
@@ -193,5 +193,21 @@ if(hasME) {
193193
}
194194

195195

196+
## trace(), debug() etc for coerce methods -- PR#18823
197+
trr <- quote(list(.Generic, .Method, .defined, .target))
198+
sig <- c("ANY", "logical")
199+
m0 <- selectMethod(coerce, signature = sig)
200+
a0 <- as(0, "logical") # just `FALSE`
201+
trace(coerce, tracer = trr, signature = sig)
202+
m1 <- selectMethod(coerce, signature = sig)
203+
a1 <- as(0, "logical") # error "object '.Generic' not found" in R <= 4.4.3
204+
untrace(coerce, signature = sig)
205+
m2 <- selectMethod(coerce, signature = sig)
206+
stopifnot( is(m0, "MethodDefinition"),
207+
!is(m0, "MethodDefinitionWithTrace"),
208+
is(m1, "MethodDefinitionWithTrace"),
209+
identical(m0, m2), identical(a0, a1))
210+
211+
196212

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

0 commit comments

Comments
 (0)
Please sign in to comment.