We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 35c1f37 commit e3e0882Copy full SHA for e3e0882
doc/NEWS.Rd
@@ -751,6 +751,9 @@
751
as \code{NA}.
752
753
\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}.
757
}
758
759
src/library/methods/R/as.R
@@ -1,7 +1,7 @@
1
# File src/library/methods/R/as.R
2
# Part of the R package, https://www.R-project.org
3
#
4
-# Copyright (C) 1995-2019 The R Core Team
+# Copyright (C) 1995-2025 The R Core Team
5
6
# This program is free software; you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
@@ -91,6 +91,9 @@ as <-
91
92
93
94
+ environment(asMethod) <- asMethodEnv <- new.env(parent = environment(asMethod))
95
+ loadMethod(asMethod, envir = asMethodEnv)
96
+ assign(".Generic", asMethod@generic, envir = asMethodEnv)
97
if(strict)
98
asMethod(object)
99
else
tests/classes-methods.R
@@ -193,5 +193,21 @@ if(hasME) {
193
194
195
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
212
213
cat('Time elapsed: ', proc.time(),'\n')
0 commit comments