[R] using trace() on S4 coerce method

About this list Date view Thread view Subject view Author view Attachment view

From: Gordon Smyth (smyth@wehi.edu.au)
Date: Thu 13 May 2004 - 17:56:45 EST


Message-id: <6.0.1.1.1.20040513174153.02a431d0@imaphost.wehi.edu.au>

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@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@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

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://www.stat.math.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


About this list Date view Thread view Subject view Author view Attachment view

This archive was generated by hypermail 2.1.3 : Mon 31 May 2004 - 23:05:09 EST