[Rd] Why cant my S4 class have a slot named `C`?
Steve Lianoglou
mailinglist.honeypot at gmail.com
Tue Feb 21 17:13:29 CET 2012
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
More information about the R-devel
mailing list