[R] alias for a class

Duncan Murdoch murdoch at stats.uwo.ca
Fri Mar 14 11:29:11 CET 2008


Christophe Genolini wrote:
> Hi the list
>
> Is it possible to give two names for a class ? One long name for using 
> in programmation, and one short name for the "quick and durty" uses ?
>   
Not easily.
> With function, we can do
>
> mcf <- myCoolFunction <- function(x)....
>   
That creates a new function which is a copy of the old one.  If one of 
them changes later, the other won't change, so it's not really an "alias".

The trouble with trying to do this with classes is that a class isn't a 
simple thing in R.  In S3, it's just a name that can be used in lots of 
places.  S4 is more structured, but still a class definition is fairly 
spread out.

So you could probably write a function that tracked down and copied all 
the pieces, but it's not easy.
> With class, I define "clusterizedLongData", I want to use it with the 
> full name when I am writing my code, but I would like something like cld 
> when I make a demo, or when I try things on console... Is it possible ?

Isn't it really the job of your text editor to make it easy to type well 
chosen names?  The GUIs in Windows and on the Mac can do name 
completion, so you don't need a lot more typing for the long name than 
the short one.  As far as I know ESS can do the same, and there are 
probably others too.  If you're not using one of those, you should be.

Duncan Murdoch



More information about the R-help mailing list