Duncan Murdoch wrote:
>
> I'm trying to get an R package I wrote to work in S-PLUS. The package
> uses S version 4 methods, and I'm getting an error where a default
> method is being called when I would have expected a more specific one
> to be called.
To verify what method is being called, you might want to use
selectMethod(f, "orientation"), or whatever the function and signature
are.
>
> Part of the problem may be that I have leftover classes or methods
> that are getting in the way. Is there a way to use the object browser
> to browse the meta data about classes? If not, is there a way to say
> "delete all the meta data, I want to start over"?
Someone else will have to answer about the object browser, but here are
a few tools at the command level.
You can find out about the metadata in several ways. The low-level way
is to use the meta=1 argument to functions such as objects():
S+> objects(meta=1)
[1] "C#A" "C#B" "C#classRepListOf"
"C#foo"
[5] "C#listOf" "C#m1" "C#n1"
"C#orientation"
[9] "C#seq2" "C#t1" "C#vectorWithTime"
"Classes"
[13] "Generics" "Groups" "M#["
"M#[<-"
[17] "M#[[<-"
But that's pretty ugly. For nearly all purposes you will be better off
with higher-level functions:
S+> getClasses(1) # show all the class definitions on database 1
[1] "A" "B" "classRepListOf" "foo"
[5] "listOf" "m1" "n1" "orientation"
[9] "seq2" "t1" "vectorWithTime"
S+> showMethods(where = 1) # show all the methods defined on database 1
$"[":
Database x
[1,] ".Data" "listOf"
$"[<-":
Database x value
[1,] ".Data" "listOf" "ANY"
$"[[<-":
Database x
[1,] ".Data" "listOf"
(As you can see, this returns a list with components for each function.)
Then, to see individual methods from this list:
S+> getMethod("[[<-", "listOf")
function(x, ..., value)
{
.........
Then individual methods can be removed by removeMethod
S+> setMethod("[", "A", function(x, ..., drop){stop("not really")})
S+> showMethods("[", where=1)
Database x
[1,] ".Data" "listOf"
[2,] ".Data" "A"
S+> removeMethod("[", "A")
[1] T
S+> showMethods("[", where=1)
Database x
[1,] ".Data" "listOf"
and all the methods can be removd by removeMethods(f, where=1), which
removes the methods metadata, and restores a nongeneric version if there
was one:
S+> foo = function(x)x
S+> setMethod("foo", "A", function(x)"A")
S+> setMethod("foo", "B", function(x)"B")
S+> removeMethods("foo")
S+> foo
function(x)
x
--
John M. Chambers jmc@bell-labs.com
Bell Labs, Lucent Technologies office: (908)582-2681
700 Mountain Avenue, Room 2C-282 fax: (908)582-3340
Murray Hill, NJ 07974 web: http://www.cs.bell-labs.com/~jmc
|