[Rd] problem subsetting of a reference class

A Zege andre.zege at gmail.com
Thu Apr 21 21:24:11 CEST 2011


I am trying to define subset operator for a reference class and hitting some
problem i am unable to diagnose.To give an example, here is a toy class
generator that is a wrapper around a list




tmpGEN<-setRefClass("TMP", fields=list(
				namelist="list"
		))
tmpGEN$methods('add'=function(obj, name){
	namelist[[name]]<<-obj
})

tmpGEN$methods('['=function(name){
			if(class(name)!="character")
				stop('to return cache element need to pass its name')
			ind<-match(name, names(namelist))
			if(is.na(ind))
				stop('data to remove is not in namelist')
			namelist[[name]]
		})


==============

when i try to use it, the following happens
v<-rnorm(10)
tmp<-tmpGEN$new()
tmp$add(v, 'random')

..... up until here everything is ok, class is generated and vector is
added. Now when i do
tmp['random']

i get error message 

Error in tmp["random"] : object of type 'S4' is not subsettable

Not sure if it means that i cannot define "[" operator for a class or if i
am doing it syntactically wrong


--
View this message in context: http://r.789695.n4.nabble.com/problem-subsetting-of-a-reference-class-tp3466690p3466690.html
Sent from the R devel mailing list archive at Nabble.com.



More information about the R-devel mailing list