[R] using trace() on S4 coerce method
Gordon Smyth
smyth at wehi.edu.au
Thu May 13 09:56:45 CEST 2004
I'm trying to use trace() on an S4 coerce method, but get the error
Error in bindingIsLocked(what, whereM) : no binding for "coerce"
What am I doing wrong? Example code follows.
(I've googled the R mailing lists for "trace coerce" and "trace
bindingisLocked" without finding anything relevant. Perhaps I should
re-define the method in terms of an ordinary function and trace the later
function, as suggested by John Chambers to another user:
https://stat.ethz.ch/pipermail/r-devel/2003-August/027249.html
But it would be nice to be able to trace the method directly.)
Thanks
Gordon
> setClass("MyClass1",representation(a="numeric"))
[1] "MyClass1"
> setClass("MyClass2",representation(a="character"))
[1] "MyClass2"
> setAs("MyClass1","MyClass2",function(from,to)
new(to,a=as.character(from at a)))
> x <- new("MyClass1",a=20)
> as(x,"MyClass2")
An object of class "MyClass2"
Slot "a":
[1] "20"
> tracingState(on=TRUE)
[1] FALSE
> getMethod("coerce",c("MyClass1","MyClass2"))
Method Definition (Class "MethodDefinition"):
function (from, to = "MyClass2", strict = TRUE)
new(to, a = as.character(from at a))
Signatures:
from to
target "MyClass1" "MyClass2"
defined "MyClass1" "MyClass2"
> trace("coerce",browser,signature=c("MyClass1","MyClass2"))
Error in bindingIsLocked(what, whereM) : no binding for "coerce"
> version
_
platform i386-pc-mingw32
arch i386
os mingw32
system i386, mingw32
status
major 1
minor 9.0
year 2004
month 04
day 12
language R
More information about the R-help
mailing list