Hi, is there a way to define a method say '$$' that would behave like '$' and allow calls like 'a$$name'? Thanks. Renaud -- Renaud Gaujoux Computational Biology - University of Cape Town South Africa ### UNIVERSITY OF CAPE TOWN This e-mail is subject to the UCT ICT policies and e-mail disclaimer published on our website at http://www.uct.ac.za/about/policies/emaildisclaimer/ or obtainable from +27 21 650 4500. This e-mail is intended only for the person(s) to whom it is addressed. If the e-mail has reached you in error, please notify the author. If you are not the intended recipient of the e-mail you may not use, disclose, copy, redirect or print the content. If this e-mail is not related to the business of UCT it is sent by the sender in the sender's individual capacity. ###
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. > > RenaudNo. 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
On 09/07/2010 8:18 AM, Renaud Gaujoux wrote:> Hi, > > is there a way to define a method say '$$' that would behave like '$' > and allow calls like 'a$$name'?No, the parser handles a fixed syntax, and that expression is not legal. You could do it with a %$$% name using the infix operator syntax. (I think the description in the R Language Definition suggests this is not legal, since $$ is not a valid name, but it does currently work and that's unlikely to change.) Duncan Murdoch
Apparently Analagous Threads
- Namespace/inheritance problem in S4 methods for a union class
- Non identical numerical results from R code vs C/C++ code?
- doMC - compiler - concatenate an expression vector into a single expression?
- Multiple sub-architecture: linking issue
- Multiple sub-architecture: linking issue