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

Robert Gentleman rgentlem at jimmy.harvard.edu
Wed Aug 6 02:26:02 MEST 2003


On Wed, Aug 06, 2003 at 06:26:53AM +0200, statwy at stat.nus.edu.sg wrote:
> 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
> 
> > new("notok",
> +    "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.

 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


> 
> Thomas
> 
> ______________________________________________
> R-devel at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-devel

-- 
+---------------------------------------------------------------------------+
| Robert Gentleman                 phone : (617) 632-5250                   |
| Associate Professor              fax:   (617)  632-2444                   |
| Department of Biostatistics      office: M1B20                            |
| Harvard School of Public Health  email: rgentlem at jimmy.harvard.edu        |
+---------------------------------------------------------------------------+



More information about the R-devel mailing list