[Rd] Why cant my S4 class have a slot named `C`?

From: Steve Lianoglou <mailinglist.honeypot_at_gmail.com>
Date: Tue, 21 Feb 2012 11:13:29 -0500


Hi all,

This feature was throwing me for a loop for quite some time until I played with the names of the slots.

Consider exhibit A:



setClass("SVM",
         representation=representation(
           x='numeric',
           y='numeric',
           C='numeric',
           eps='numeric'),
         prototype=prototype(
           x=numeric(),
           y=numeric(),
           C=numeric(),
           eps=numeric()))

SVM <- function(x, y, C, eps) {
  new("SVM", x=x, y=y, C=C, eps=eps)
}

And now a call to my "constructor"

R> SVM(1:10, 1:10, 1, 0.5)
Error in .getClassFromCache(Class, where) :   Class should be either a character-string name or a class definition


This error occurs with both R-2.14.1 and R-devel

Changing the name name from `C` to `Cost` fixes it:



setClass("svm",
         representation=representation(
           x='numeric',
           y='numeric',
           Cost='numeric',
           eps='numeric'),
         prototype=prototype(
           x=numeric(),
           y=numeric(),
           Cost=numeric(),
           eps=numeric()))

svm <- function(x, y, Cost, eps) {
  new("svm", x=x, y=y, Cost=Cost, eps=eps)
}

R> svm(1:10, 1:10, 1, 0.5)
An object of class "svm"
Slot "x":
 [1] 1 2 3 4 5 6 7 8 9 10

Slot "y":
 [1] 1 2 3 4 5 6 7 8 9 10

Slot "Cost":
[1] 1

Slot "eps":
[1] 0.


I was fishing around the R-devel mailing list w/ that error message to see if anything turned up but I wasn't having any luck so it took a while to figure out what was going on.

Is this known/intended behavior? Maybe I missed it in the documentation (not sure where that might have been)? If it is intended, maybe a better error message would be more useful?

Thanks,
-steve

-- 
Steve Lianoglou
Graduate Student: Computational Systems Biology
 | Memorial Sloan-Kettering Cancer Center
 | Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact

______________________________________________
R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Tue 21 Feb 2012 - 16:15:41 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 21 Feb 2012 - 17:30:19 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive