[Rd] "[" operator and indexing ambiguity

Oleg Sklyar osklyar at ebi.ac.uk
Sat Jan 27 01:30:51 CET 2007


Hi everybody. I myself am not subscribed for Rd therefore replying late. 
As the author of EBImage, I'd like to comment on the issue.

As Tony correctly writes one can generally use nargs() to get the number 
of arguments, and this works for "["(x,i,j,...,drop) method as well. The 
problem I had with the EBImage where I could not distinguish between 
x[index] and x[index,,] is that somehow particularly for the "[" method 
and particularly for 3 dimensions nargs in both cases gave me the same 
number of arguments! This behavior was not present when the number of 
dimension was 2 or 4, i.e. for x[index,] or x[index,,,] -- these could 
be easily distinguished from x[index]. Anyway, maybe R changed since and 
I just did not notice that :)

Otherwise, coming back to Bradley's original question, it is generally a 
  difficult task to implement correct indexing if your underlying type 
does not initially support it simply because there are so many 
combinations possible! Originally, EBImage's Image class was not based 
on 'array' and then "[" method definitions were simply overwhelming -- 
too many and too long, and still did not work completely right. Using 
array simply allowed me to pass the arguments as they are to the 
underlying array and only build a couple of features on top.

It becomes even more difficult for the set method "[<-" as you really 
need to parse all indexes and make them rotating if too short etc etc. 
Here the power of R in freestyle indexing of arrays becomes a pain.


-- 
Dr Oleg Sklyar | EBI-EMBL, Cambridge CB10 1SD, UK | +44-1223-494466



More information about the R-devel mailing list