Re: [Rd] Defining a method that behaves like '$'?

From: Romain Francois <romain.francois_at_dbmail.com>
Date: Fri, 09 Jul 2010 14:27:53 +0200

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

______________________________________________
R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Fri 09 Jul 2010 - 12:30:34 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 11 Jul 2010 - 21:30:14 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive