[R] Functional pattern-matching in R

Alexy Khrabrov deliverable at gmail.com
Wed Oct 29 21:39:27 CET 2008


I found there's a very good functional set of operations in R, such as  
apply family, Hadley Wickham's lovely plyr, etc.  There's even a  
Reduce (a.k.a. fold).  Now I wonder how can we do pattern-matching?

E.g., now I split dimensions like this:

	m <- dim(V)[1] # R
	n <- dim(V)[2]  # still R

While even Matlab allows for

[m,n] = size(V) % MATLAB!

Ideally I'd be able to say,

<<x,y>> <- dim(V)

-- where <<.,.>> is some magic needed.

Similarly, to break lists, we'd need, in a MLish notation,

match L with
| head::tail => ...
| () => ;

What can be done in R now to simulate it, and/or how Rish is it to add  
something like that?

Cheers,
Alexy



More information about the R-help mailing list