[R] assignment functions with inherited class error

egc enrique.garzo.cano at gmail.com
Wed Aug 11 13:42:22 CEST 2010


# Two test for a class like this:
setClass("XXX",
representation=representation(
"matrix"
)
)

i<-new("XXX");
m=matrix();
colnames(m)<-c("colA");
i en .Data=m;
# >i
# An object of class “XXX”
#     colA
#[1,]   NA
#________________________________________________________________________
#First Test 
"varnames<-" <- function(x,value){
colnames(x en .Data)<-value;
}
#==========================================================
#Result:
# > varnames(i)<-c("a")
# > i
# [1] "a"
# x lost class type an value from XXX to vector.  

#________________________________________________________________________
# Second Test

"varnames<-" <- function(x,value){
m=x en .Data;
colnames(m)<-value;
print(names(m)) #Ok the matrix is here. 
slot(x,".Data")<-m;
}
#=========================================================
#Result: 
# x lost class type and value from XXX to matrix.
# > varnames(i)<-c("colT") 
# > i
#     colT
# [1,]   NA
# > class(i)
# [1] "matrix"

some idea?

Enrique Garzo Cano
-Biology Graduate. Ph.D. student.-
enrique.garzo.cano en gmail.com
Departamento de Ciencias Biomédicas (Área de Fisiología) 
Facultad de Veterinaria Universidad de León 
24071 León (Spain) 
Tel: +34 987 291981 
Fax: +34 987 291267



More information about the R-help mailing list