[R] "aliases" for R constructs?

(Ted Harding) Ted.Harding at nessie.mcc.ac.uk
Mon Oct 20 21:38:01 CEST 2003


Hi Folks,

My recent response to Laura Quinn's query about matrix subsetting
reminded of a question.

I wrote:

  iDir <- ((Winds[,20]<45)|(Winds[,20]>315))&(!is.na(Winds[,20]))

Now, I find "!is.na" a bit awkward to type, so I might prefer to
type it as "nis.na".

While it is possible to define

  nis.na <- function(x){ !is.na(x) }

this involves a slight bloat of overhead in execution since achieving
!is.na involves an extra layer of function call. So is it possible
to define an "alias" so that

  nis.na(x)

is _exactly_ equivalent to

  !is.na(x)

?

This is not quite the same as defining a simple alias for the name of
a function or other object, though I'd be very interested to know if
this can be done too.

I'm thinking of something which would work like the 'define'
mechanism in C (and some other languages), where

  #define nis.na !is.na

would cause simple substitution of "!is.na" for "nis.na" on input
(and you can have parametrised defines too).

With thanks,
Ted.



--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at nessie.mcc.ac.uk>
Fax-to-email: +44 (0)870 167 1972
Date: 20-Oct-03                                       Time: 20:38:01
------------------------------ XFMail ------------------------------




More information about the R-help mailing list