From andre.zege at gmail.com  Thu Apr 21 21:24:11 2011
From: andre.zege at gmail.com (A Zege)
Date: Thu, 21 Apr 2011 12:24:11 -0700 (PDT)
Subject: [Rd] problem subsetting of a reference class
Message-ID: <1303413851743-3466690.post@n4.nabble.com>

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.



[Rd] problem subsetting of a reference class
A Zege