From romain.francois at dbmail.com  Fri Jul  9 14:27:53 2010
From: romain.francois at dbmail.com (Romain Francois)
Date: Fri, 09 Jul 2010 14:27:53 +0200
Subject: [Rd] Defining a method that behaves like '$'?
In-Reply-To: <4C371398.80603@cbio.uct.ac.za>
References: <4C371398.80603@cbio.uct.ac.za>
Message-ID: <4C3715C9.9070505@dbmail.com>


Le 09/07/10 14:18, Renaud Gaujoux a ?crit :
>
> Hi,
>
> is there a way to define a method say '$$' that would behave like '$'
> and allow calls like 'a$$name'?
> Thanks.
>
> Renaud

No. This is not grammatically valid syntax:

 > parse( text = 'a$$name' )
Erreur dans parse(text = "a$$name") : '$' inattendu(e) dans "a$$"


But you can define custom methods for $.

setClass( "Foo", representation( n = "integer" ) )
setMethod( "$", "Foo", function(x, name ){
	function( ) rnorm( x at n )
} )
foo <- new( "Foo", n = 10L )
foo$bla( )


Romain

-- 
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://bit.ly/aJHNLV : Rmetrics slides
|- http://bit.ly/98Uf7u : Rcpp 0.8.1
`- http://bit.ly/c6YnCi : graph gallery collage



[Rd] Defining a method that behaves like '$'?
Romain Francois