Skip to content

S4 methods bug in naming of slots (PR#3665)

2 messages · statwy@stat.nus.edu.sg, Robert Gentleman

#
Hello,

I am using R 1.7.1 on a Redhat Linux machine, version 7.3.
The following works fine: 

setClass("ok", representation(
      "A"       = "matrix",
      "Cmatrix" = "matrix"))

new("ok",
    "A" = diag(4),
    "Cmatrix" = diag(4))

But the following doesn't work:

setClass("notok", representation(
      "A" = "matrix",
      "C" = "matrix"))

new("notok",
    "A" = diag(4),
    "C" = diag(4))

It says
+    "A" = diag(4),
+    "C" = diag(4))
Error in methodsPackageMetaName("C", name) :
        The name of the object (e.g,. a class or generic function) to find in the meta-data must be a single string (got an object of class "matrix")

Can this bug be fixed? It doesn't work in the Windows version either. 
Thanks in advance.

Thomas
#
On Wed, Aug 06, 2003 at 06:26:53AM +0200, statwy@stat.nus.edu.sg wrote:
It is not really a bug. If you look at the definition of the function
 new you will see that its first argument is named Class. The argument
 you want to use for the C slot gets matched to the Class argument -
 it isn't a class and you get an error message. So, to avoid
 the partial matching algorithm for matching fucntions arguments you
 would need to go:
 
  new(Class="notok", A=diag(4), C=diag(4))

 which does work. Note also, no need for quotes around A and C.

 Robert